我想处理子流程的输出,并决定在收到足够的输出后终止该子流程。我的程序逻辑决定我们何时有足够的输入。在
示例:等待Udev事件
try:
for event in sh.udevadm('monitor', _iter=True):
if event matches usb stick added:
print("Ok, I will work with that USB stick you just plugged in!")
break
except:
pass
print("I copy stuff on your USB stick now!")
“break”终止进程,但我无法捕获异常:
终止子进程的正确方法是什么?或者如何处理异常?在
也许您最好直接使用
subprocess.Popen
而不是sh
库。在类似于:
找到了一种使用交互式回调的方法。在
http://amoffat.github.io/sh/#interactive-callbacks
我觉得挺不错的。在
相关问题 更多 >
编程相关推荐