[英]Python waiting for subprocess to finish
我对Python真的很陌生,并且子流程类有一些问题。
我正在使用来启动外部程序:
thread1.event.clear()
thread2.event.clear()
print "Sende Motoren STOP"
print "Gebe BILD in Auftrag"
proc = Popen(['gphoto2 --capture-image &'], shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
sleep (args.max+2)
thread1.event.set()
thread2.event.set()
sleep (args.tp-2-args.max)
我的问题是,在我启动Python脚本的shell中,我仍然获得GPHOTO2
的输出,并且我认为Python仍在等待GPHOTO完成。
有任何想法吗?
subprocess.Pope
的文档指出:
stdin, stdout and stderr specify the executed programs' standard
input, standard output and standard error file handles, respectively.
[...]
With None, no redirection will occur; the child's file handles will be
inherited from the parent.
因此,您可能想尝试一些类似的方法。 顺便说一句。 直到完成为止。 因此,您可能不需要sleep()
(这里可能需要subprocess.Popen中的wait()
吗?)。
import subprocess
ret_code = subprocess.call(["echo", "Hello World!"], stdout=subprocess.PIPE);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.