From 9ed63e06c4df5c99b3d85eee32e7f106290fd04a Mon Sep 17 00:00:00 2001 From: David Foster Date: Mon, 8 Jan 2024 10:29:54 -0500 Subject: [PATCH] SQ -> Shell: Fix race condition where shell might start accepting commands before foreground thread created --- src/crystal/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/crystal/main.py b/src/crystal/main.py index 430afa6e..52395738 100644 --- a/src/crystal/main.py +++ b/src/crystal/main.py @@ -286,6 +286,9 @@ def _finish_launch(self, filepath: Optional[str]=None) -> None: from crystal.util.xthreading import is_quitting, set_foreground_thread set_foreground_thread(threading.current_thread()) try: + # (Don't insert anything between set_foreground_thread() and MyApp()) + app = MyApp(redirect=False) + # Start shell if requested if parsed_args.shell: from crystal.shell import Shell @@ -293,8 +296,6 @@ def _finish_launch(self, filepath: Optional[str]=None) -> None: else: shell = None - app = MyApp(redirect=False) - # Starts tests if requested if parsed_args.test is not None: from crystal.util.xthreading import bg_call_later, fg_call_later, has_foreground_thread