From 6f96498de66358b89f3a2035627eed2e02dde5a1 Mon Sep 17 00:00:00 2001 From: Mathias Guijarro Date: Thu, 13 Jun 2024 10:03:37 +0200 Subject: [PATCH] fix: do not import "server" in client, prevents from having trouble with QApplication creation order Like with QtWebEngine --- bec_widgets/cli/client_utils.py | 13 ++++++------- bec_widgets/cli/server.py | 6 +++++- pyproject.toml | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bec_widgets/cli/client_utils.py b/bec_widgets/cli/client_utils.py index e9d18d0c..670e5ed1 100644 --- a/bec_widgets/cli/client_utils.py +++ b/bec_widgets/cli/client_utils.py @@ -86,13 +86,8 @@ def _start_plot_process(gui_id, gui_class, config) -> None: Start the plot in a new process. """ # pylint: disable=subprocess-run-check - monitor_module = importlib.import_module("bec_widgets.cli.server") - monitor_path = monitor_module.__file__ - command = [ - sys.executable, - "-u", - monitor_path, + "bec-gui-server", "--id", gui_id, "--config", @@ -100,7 +95,11 @@ def _start_plot_process(gui_id, gui_class, config) -> None: "--gui_class", gui_class.__name__, ] - process = subprocess.Popen(command, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + env_dict = os.environ.copy() + env_dict["PYTHONUNBUFFERED"] = "1" + process = subprocess.Popen( + command, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env_dict + ) process_output_processing_thread = threading.Thread(target=_get_output, args=(process,)) process_output_processing_thread.start() return process, process_output_processing_thread diff --git a/bec_widgets/cli/server.py b/bec_widgets/cli/server.py index 2d39ccf3..56142fb6 100644 --- a/bec_widgets/cli/server.py +++ b/bec_widgets/cli/server.py @@ -114,7 +114,7 @@ class BECWidgetsCLIServer: self.client.shutdown() -if __name__ == "__main__": # pragma: no cover +def main(): import argparse import os import sys @@ -166,3 +166,7 @@ if __name__ == "__main__": # pragma: no cover app.aboutToQuit.connect(server.shutdown) sys.exit(app.exec()) + + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/pyproject.toml b/pyproject.toml index b07d8239..f2e9b540 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ Homepage = "https://gitlab.psi.ch/bec/bec_widgets" [project.scripts] bw-generate-cli = "bec_widgets.cli.generate_cli:main" +bec-gui-server = "bec_widgets.cli.server:main" [tool.hatch.build.targets.wheel] include = ["*"]