Skip to content

Commit d4134f5

Browse files
Berserker66FlySniper
authored andcommitted
Launcher: keep alive (ArchipelagoMW#1894)
1 parent 079da73 commit d4134f5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Launcher.py

+12
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ def component_action(button):
223223
else:
224224
launch(get_exe(button.component), button.component.cli)
225225

226+
def _stop(self, *largs):
227+
# ran into what appears to be https://groups.google.com/g/kivy-users/c/saWDLoYCSZ4 with PyCharm.
228+
# Closing the window explicitly cleans it up.
229+
self.root_window.close()
230+
super()._stop(*largs)
231+
226232
Launcher().run()
227233

228234

@@ -267,3 +273,9 @@ def main(args: Optional[Union[argparse.Namespace, dict]] = None):
267273
help="Pass either a patch file, a generated game or the name of a component to run.")
268274
parser.add_argument('args', nargs="*", help="Arguments to pass to component.")
269275
main(parser.parse_args())
276+
277+
from worlds.LauncherComponents import processes
278+
for process in processes:
279+
# we await all child processes to close before we tear down the process host
280+
# this makes it feel like each one is its own program, as the Launcher is closed now
281+
process.join()

worlds/LauncherComponents.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import weakref
12
from enum import Enum, auto
23
from typing import Optional, Callable, List, Iterable
34

@@ -48,10 +49,14 @@ def handles_file(self, path: str):
4849
def __repr__(self):
4950
return f"{self.__class__.__name__}({self.display_name})"
5051

52+
processes = weakref.WeakSet()
53+
5154
def launch_subprocess(func: Callable, name: str = None):
55+
global processes
5256
import multiprocessing
53-
process = multiprocessing.Process(target=func, name=name, daemon=True)
57+
process = multiprocessing.Process(target=func, name=name)
5458
process.start()
59+
processes.add(process)
5560

5661
class SuffixIdentifier:
5762
suffixes: Iterable[str]

0 commit comments

Comments
 (0)