diff --git a/src/tribler-gui/tribler_gui/core_manager.py b/src/tribler-gui/tribler_gui/core_manager.py index 2cfa8ddda32..86fb39e4e17 100644 --- a/src/tribler-gui/tribler_gui/core_manager.py +++ b/src/tribler-gui/tribler_gui/core_manager.py @@ -51,49 +51,6 @@ def on_core_connected(self, _): if not self.core_finished: self.core_connected = True - def on_core_stdout_read_ready(self): - raw_output = bytes(self.core_process.readAllStandardOutput()) - self.last_core_stdout_output = raw_output.decode("utf-8").strip() - try: - print(self.last_core_stdout_output) # print core output # noqa: T001 - except OSError: - # Possible reason - cannot write to stdout as it was already closed during the application shutdown - if not self.quitting_app: - raise - - def on_core_stderr_read_ready(self): - raw_output = bytes(self.core_process.readAllStandardError()) - self.last_core_stderr_output = raw_output.decode("utf-8").strip() - try: - print(self.last_core_stderr_output, file=sys.stderr) # print core output # noqa: T001 - except OSError: - # Possible reason - cannot write to stdout as it was already closed during the application shutdown - if not self.quitting_app: - raise - - def on_core_started(self): - self.core_started = True - self.core_running = True - - def on_core_finished(self, exit_code, exit_status): - self.core_running = False - self.core_finished = True - if self.shutting_down: - if self.should_quit_app_on_core_finished: - self.quit_application() - else: - error_message = ( - f"The Tribler core has unexpectedly finished with exit code {exit_code} and status: {exit_status}!\n" - f"Last core output: \n {self.last_core_stderr_output or self.last_core_stdout_output}" - ) - self._logger.warning(error_message) - - # Stop the event manager loop if it is running - if self.events_manager.connect_timer and self.events_manager.connect_timer.isActive(): - self.events_manager.connect_timer.stop() - - raise CoreCrashedError(error_message) - def start(self, core_args=None, core_env=None, upgrade_manager=None, run_core=True): """ First test whether we already have a Tribler process listening on port . @@ -139,6 +96,30 @@ def start_tribler_core(self): connect(self.core_process.finished, self.on_core_finished) self.core_process.start(sys.executable, core_args) + def on_core_started(self): + self.core_started = True + self.core_running = True + + def on_core_stdout_read_ready(self): + raw_output = bytes(self.core_process.readAllStandardOutput()) + self.last_core_stdout_output = raw_output.decode("utf-8").strip() + try: + print(self.last_core_stdout_output) # print core output # noqa: T001 + except OSError: + # Possible reason - cannot write to stdout as it was already closed during the application shutdown + if not self.quitting_app: + raise + + def on_core_stderr_read_ready(self): + raw_output = bytes(self.core_process.readAllStandardError()) + self.last_core_stderr_output = raw_output.decode("utf-8").strip() + try: + print(self.last_core_stderr_output, file=sys.stderr) # print core output # noqa: T001 + except OSError: + # Possible reason - cannot write to stdout as it was already closed during the application shutdown + if not self.quitting_app: + raise + def stop(self, quit_app_on_core_finished=True): if quit_app_on_core_finished: self.should_quit_app_on_core_finished = True @@ -153,6 +134,25 @@ def stop(self, quit_app_on_core_finished=True): self.events_manager.shutting_down = True TriblerNetworkRequest("shutdown", lambda _: None, method="PUT", priority=QNetworkRequest.HighPriority) + def on_core_finished(self, exit_code, exit_status): + self.core_running = False + self.core_finished = True + if self.shutting_down: + if self.should_quit_app_on_core_finished: + self.quit_application() + else: + error_message = ( + f"The Tribler core has unexpectedly finished with exit code {exit_code} and status: {exit_status}!\n" + f"Last core output: \n {self.last_core_stderr_output or self.last_core_stdout_output}" + ) + self._logger.warning(error_message) + + # Stop the event manager loop if it is running + if self.events_manager.connect_timer and self.events_manager.connect_timer.isActive(): + self.events_manager.connect_timer.stop() + + raise CoreCrashedError(error_message) + def quit_application(self): if not self.quitting_app: self.quitting_app = True