Python 我怎么知道子流程正在GUI上等待输入
我正在编写一个顶层脚本(python)来控制IC设计流程上的EDA工具,顶层脚本有一个GUI(python tkinter),使用subprocess.Popen()运行EDA工具,在GUI上打印标准输出 有时EDA工具不会退出,而是等待输入,然后GUI将挂起并等待我的输入,但top脚本无法从subprocess.stdout捕获正确的stdout消息,并且无法将我的输入放入subprocess 下面是我的主要脚本的一部分Python 我怎么知道子流程正在GUI上等待输入,python,multithreading,tkinter,subprocess,Python,Multithreading,Tkinter,Subprocess,我正在编写一个顶层脚本(python)来控制IC设计流程上的EDA工具,顶层脚本有一个GUI(python tkinter),使用subprocess.Popen()运行EDA工具,在GUI上打印标准输出 有时EDA工具不会退出,而是等待输入,然后GUI将挂起并等待我的输入,但top脚本无法从subprocess.stdout捕获正确的stdout消息,并且无法将我的输入放入subprocess 下面是我的主要脚本的一部分 class runBlocks(): ... ... d
class runBlocks():
... ...
def subprocessRun(self):
# run EDA tool "runCommand" with subprocess.Popen.
self.RC = subprocess.Popen(runCommand, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# save subprocess stdout into queue.
self.queue = queue.Queue()
getRunProcessThread = threading.Thread(target=self.getRunProcess)
getRunProcessThread.setDaemon(True)
getRunProcessThread.start()
# update GUI with the stdout (on queue).
self.updateRunProcess()
# wait for subprocess finish.
(stdout, stderr) = self.RC.communicate()
return(self.RC.returncode)
def getRunProcess(self):
# no block getting subprocess.stdout
while self.RC.poll() == None:
stdoutLine = str(self.RC.stdout.readline(), encoding='utf-8')
self.queue.put(stdoutLine)
def updateRunProcess(self):
# if there is still something from subprocess.stdout, print them into GUI Text.
while self.RC.poll() == None or not self.queue.empty():
if self.queue.empty():
time.sleep(0.1)
conitnue
else:
line = self.queue.get_nowait()
if line:
# "self.runProcessText" is a Text on GUI, accept EDA tool output message.
self.runProcessText.insert(END, line)
# "self.runProcessText" is on "self.frame6", after inserting new message, update the frame.
self.frame6.update()
self.runProcessText.see(END)
如果我直接在终端上运行EDA工具,它将停止并等待我的输入
$ dc_shell-t -64 -topo -f ./analyze.run.tcl -o analyze.log
...
$ #quit
$ dc_shell-topo>
如果我使用top脚本运行EDA工具,subprocess.stdout将在消息“退出”时停止,我无法获得消息“dc#u shell-topo>”
我知道子进程正在等待我的输入,但GUI将在消息“退出”时停止,并在while命令上挂起“time.sleep(0.1)”
我还尝试将“time.sleep(0.1)”替换为“self.GUItop.after(100,self.updateRunProcess)”,然后stdout将在没有任何输入的情况下执行“dc_shell-topo>”命令,然后直接完成
...
dc_shell=topo>
Memory usage for main task 82 Mbytes.
CPU usage for this session 6 seconds ...
Thank you...
我的预期行为是:
...
dc_shell=topo>
Memory usage for main task 82 Mbytes.
CPU usage for this session 6 seconds ...
Thank you...