Skip to content

Commit

Permalink
Launcher: keep alive (ArchipelagoMW#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
Berserker66 authored Jun 27, 2023
1 parent a7bc884 commit a4e485e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ def component_action(button):
else:
launch(get_exe(button.component), button.component.cli)

def _stop(self, *largs):
# ran into what appears to be https://groups.google.com/g/kivy-users/c/saWDLoYCSZ4 with PyCharm.
# Closing the window explicitly cleans it up.
self.root_window.close()
super()._stop(*largs)

Launcher().run()


Expand Down Expand Up @@ -267,3 +273,9 @@ def main(args: Optional[Union[argparse.Namespace, dict]] = None):
help="Pass either a patch file, a generated game or the name of a component to run.")
parser.add_argument('args', nargs="*", help="Arguments to pass to component.")
main(parser.parse_args())

from worlds.LauncherComponents import processes
for process in processes:
# we await all child processes to close before we tear down the process host
# this makes it feel like each one is its own program, as the Launcher is closed now
process.join()
7 changes: 6 additions & 1 deletion worlds/LauncherComponents.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import weakref
from enum import Enum, auto
from typing import Optional, Callable, List, Iterable

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

processes = weakref.WeakSet()

def launch_subprocess(func: Callable, name: str = None):
global processes
import multiprocessing
process = multiprocessing.Process(target=func, name=name, daemon=True)
process = multiprocessing.Process(target=func, name=name)
process.start()
processes.add(process)

class SuffixIdentifier:
suffixes: Iterable[str]
Expand Down

0 comments on commit a4e485e

Please sign in to comment.