从gevent-subprocess获取实时标准输出? [英] Get live stdout from gevent-subprocess?

查看:108
本文介绍了从gevent-subprocess获取实时标准输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过POPEN获得进程的标准输出. 使用gevent 1.0,readline()和read()仍会阻塞进程并等待进程完成. 有什么线索吗?是的,我在高端和低端搜索了一个简单的解决方案.必须没有线程,对吧?

I'm trying to get the stdout of a process via POPEN as soon as it's there. With gevent 1.0 readline() and read() still block process and wait for process to finish. Any clues? And yes, I searched high and low for a simple solution. It has to be possible without threading, right?

推荐答案

我用一点技巧解决了这个问题.每当将一行写入标准输出时,只需刷新带有self.stream.flush()的Python行缓冲区和一个帮助器类即可.

I solved this using a little hack. Just flush Pythons line-buffer w/ self.stream.flush() and a helper class whenever a line is written to stdout.

这篇关于从gevent-subprocess获取实时标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆