From 8f645138bc4ba62f984c1931034547606c4e4ea4 Mon Sep 17 00:00:00 2001 From: Alexander Kozlovsky Date: Mon, 2 May 2022 10:29:19 +0200 Subject: [PATCH] Delay CodeExecutor start until the Tribler core is connected to GUI --- src/tribler/gui/code_executor.py | 15 +++++++++++++-- src/tribler/gui/tribler_app.py | 2 ++ src/tribler/gui/tribler_window.py | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/tribler/gui/code_executor.py b/src/tribler/gui/code_executor.py index 7df67106b92..68ecb2477f1 100644 --- a/src/tribler/gui/code_executor.py +++ b/src/tribler/gui/code_executor.py @@ -27,15 +27,26 @@ class CodeExecutor: def __init__(self, port, shell_variables=None): self.logger = logging.getLogger(self.__class__.__name__) + self.port = port self.tcp_server = QTcpServer() self.sockets = [] self.stack_trace = None - if not self.tcp_server.listen(port=port): + self.shell = Console(locals=shell_variables or {}, logger=self.logger) + self.started = False + + def on_core_connected(self, _): + self.logger.info('Core connected, starting code executor') + + if self.started: + return + + if not self.tcp_server.listen(port=self.port): self.logger.error("Unable to start code execution socket! Error: %s", self.tcp_server.errorString()) else: connect(self.tcp_server.newConnection, self._on_new_connection) - self.shell = Console(locals=shell_variables or {}, logger=self.logger) + self.started = True + self.logger.info('Code executor started') def _on_new_connection(self): self.logger.info("CodeExecutor has new connection") diff --git a/src/tribler/gui/tribler_app.py b/src/tribler/gui/tribler_app.py index 51eeddb12b8..97a5ddadf19 100644 --- a/src/tribler/gui/tribler_app.py +++ b/src/tribler/gui/tribler_app.py @@ -50,8 +50,10 @@ def parse_sys_args(self, args): variables.update(locals()) variables['window'] = self.tribler_window self.code_executor = CodeExecutor(5500, shell_variables=variables) + connect(self.tribler_window.events_manager.core_connected, self.code_executor.on_core_connected) connect(self.tribler_window.tribler_crashed, self.code_executor.on_crash) + if '--testnet' in sys.argv[1:]: os.environ['TESTNET'] = "YES" if '--trustchain-testnet' in sys.argv[1:]: diff --git a/src/tribler/gui/tribler_window.py b/src/tribler/gui/tribler_window.py index 4d8b59ebefa..943a331996b 100644 --- a/src/tribler/gui/tribler_window.py +++ b/src/tribler/gui/tribler_window.py @@ -199,8 +199,8 @@ def __init__( self.core_env = core_env error_handler = ErrorHandler(self) - events_manager = EventRequestManager(api_port, api_key, error_handler) - self.core_manager = CoreManager(self.root_state_dir, api_port, api_key, app_manager, events_manager) + self.events_manager = EventRequestManager(api_port, api_key, error_handler) + self.core_manager = CoreManager(self.root_state_dir, api_port, api_key, app_manager, self.events_manager) self.version_history = VersionHistory(self.root_state_dir) self.upgrade_manager = UpgradeManager(self.version_history) self.pending_requests = {}