Get live stdout from gevent-subprocess?(从 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 获取实时标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 gevent-subprocess 获取实时标准输出?


- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01