Core: Add launch function to call launch_subprocess only if multiprocessing is actually necessary (#4237)
* skips opening a subprocess if kivy (and thus the launcher gui) hasn't been loaded so stdin can function as expected on --nogui and similar * this exists lol * keep old function around and use new function for CC component * fix name=None typing
This commit is contained in:
		
							parent
							
								
									bb0948154d
								
							
						
					
					
						commit
						7474c27372
					
				| 
						 | 
				
			
			@ -87,7 +87,7 @@ class Component:
 | 
			
		|||
processes = weakref.WeakSet()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def launch_subprocess(func: Callable, name: str = None, args: Tuple[str, ...] = ()) -> None:
 | 
			
		||||
def launch_subprocess(func: Callable, name: str | None = None, args: Tuple[str, ...] = ()) -> None:
 | 
			
		||||
    global processes
 | 
			
		||||
    import multiprocessing
 | 
			
		||||
    process = multiprocessing.Process(target=func, name=name, args=args)
 | 
			
		||||
| 
						 | 
				
			
			@ -95,6 +95,14 @@ def launch_subprocess(func: Callable, name: str = None, args: Tuple[str, ...] =
 | 
			
		|||
    processes.add(process)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def launch(func: Callable, name: str | None = None, args: Tuple[str, ...] = ()) -> None:
 | 
			
		||||
    from Utils import is_kivy_running
 | 
			
		||||
    if is_kivy_running():
 | 
			
		||||
        launch_subprocess(func, name, args)
 | 
			
		||||
    else:
 | 
			
		||||
        func(*args)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SuffixIdentifier:
 | 
			
		||||
    suffixes: Iterable[str]
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -111,7 +119,7 @@ class SuffixIdentifier:
 | 
			
		|||
 | 
			
		||||
def launch_textclient(*args):
 | 
			
		||||
    import CommonClient
 | 
			
		||||
    launch_subprocess(CommonClient.run_as_textclient, name="TextClient", args=args)
 | 
			
		||||
    launch(CommonClient.run_as_textclient, name="TextClient", args=args)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _install_apworld(apworld_src: str = "") -> Optional[Tuple[pathlib.Path, pathlib.Path]]:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue