如何解决通过 EXE 运行程序时的延迟和滞后问题?
问题内容
我正在开发一个传感器读取程序,其中该程序的一部分涉及当金属目标进一步或靠近传感器时打印出传感器状态的实时更新。 “main_gui.py”文件将首先运行,一旦用户单击“开始数据检索”按钮,它将启动子进程“ies2v2.py”,在其中执行传感器读取过程并打印出来。
下面的代码显示了最初在控制台中打印的代码如何被打印到 gui 中。
def start_data_retrieval(self): 1. start a new thread for data retrieval threading.thread(target=self.retrieve_data_thread).start() def retrieve_data_thread(self): selected_current = loadcurrent[currentgrp.get()] selected_output = outputtype[outputgrp.get()] print(f"selected current: {selected_current}, selected output: {selected_output}") with subprocess.popen(["python", "ies2v2.py", "--port", self._port, "--current", selected_current.name, "--output", selected_output.name], stdout=subprocess.pipe, stderr=subprocess.stdout) as process: for line in process.stdout: line = line.decode() # defaulting to system encoding text_box.insert(end, line) text_box.update() text_box.see(end) process.poll()登录后复制