Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我怎么知道子流程正在GUI上等待输入_Python_Multithreading_Tkinter_Subprocess - Fatal编程技术网

Python 我怎么知道子流程正在GUI上等待输入

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

我正在编写一个顶层脚本(python)来控制IC设计流程上的EDA工具,顶层脚本有一个GUI(python tkinter),使用subprocess.Popen()运行EDA工具,在GUI上打印标准输出

有时EDA工具不会退出,而是等待输入,然后GUI将挂起并等待我的输入,但top脚本无法从subprocess.stdout捕获正确的stdout消息,并且无法将我的输入放入subprocess

下面是我的主要脚本的一部分

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>”停止命令时,我可以使用subprocess.stdout获取消息

  • GUI在等待输入时不会挂起

  • 我的问题是:

  • 为什么使用“time.sleep()”和“self.GUItop.after()”会影响subprocess.stdout消息

  • 当EDA工具在子流程上等待带有消息“dc_shell-topo>”的输入时,我如何在subprocess.stdout()上获得这样的消息

  • 当使用self.GUItop.after时,子进程完成之前的GUI文本(它正在等待cpu空闲),但如果没有self.GUItop.after,GUI将挂起time.sleep()命令,如何解决此问题

  • 我认为这真的是一个令人头痛的问题,我在谷歌上读过数千个相关问题,但没有一个能回答我的问题

    ...
    dc_shell=topo>
    Memory usage for main task 82 Mbytes.
    CPU usage for this session 6 seconds ...
    Thank you...