是否可以强制阻塞进程变为非阻塞?

问题描述

我有 GUI 应用程序。我想在阻塞模式下运行某个进程,并将其行为更改为非阻塞以响应 stdout 的某些特定输出。是否可以在不将我的代码打包到线程中的情况下执行此操作?

示例代码:

    def _run_streamlink(self,url,quality='worst'):
        # run process in blocking mode
        with subprocess.Popen(['streamlink',quality,'-p','mpv'],stdout=subprocess.PIPE,stderr=subprocess.DEVNULL) as p:
            while p.stdout:
                # read lines from stdout
                l = p.stdout.readline()
    
                # if certain line is detected then stop blocking main window
                if b'Writing stream to output' in l:
                    # how to force blocking process to become non blockung?
                    p.stdout.close()
                    break
    
        # process exited from loop but it still blocks UI window

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)