Skip to content

Commit

Permalink
Shell: Fix race condition where shell might start accepting commands …
Browse files Browse the repository at this point in the history
…before foreground thread created
  • Loading branch information
davidfstr committed Jan 8, 2024
1 parent ff5f607 commit ea2c831
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/crystal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,6 @@ def _main(args: List[str]) -> None:
install_to_linux_desktop_environment()
sys.exit()

# Start shell if requested
if parsed_args.shell:
from crystal.shell import Shell
shell = Shell()
else:
shell = None

# Start GUI subsystem
import wx
import wx.xml # required by wx.richtext; use explicit import as hint to py2app
Expand Down Expand Up @@ -293,6 +286,13 @@ 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:
# Start shell if requested
if parsed_args.shell:
from crystal.shell import Shell
shell = Shell()
else:
shell = None

app = MyApp(redirect=False)

# Starts tests if requested
Expand Down
3 changes: 3 additions & 0 deletions src/crystal/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class Shell:
def __init__(self) -> None:
if not has_foreground_thread():
raise ValueError('Expected there to be a foreground thread when starting a Shell')

# Setup proxy variables for shell
_Proxy._patch_help()
self._project_proxy = _Proxy(f'<unset {Project.__module__}.{Project.__name__} proxy>')
Expand Down

0 comments on commit ea2c831

Please sign in to comment.