[英]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.