Skip to content

Commit

Permalink
Delay CodeExecutor start until the Tribler core is connected to GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed May 12, 2022
1 parent d901ce0 commit 8f64513
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/tribler/gui/code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/tribler/gui/tribler_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]:
Expand Down
4 changes: 2 additions & 2 deletions src/tribler/gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 8f64513

Please sign in to comment.