[英]Can subprocess.call be invoked without waiting for process to finish?
I'm currently using subprocess.call() to invoke another program, but it blocks the executing thread until that program finishes.我目前正在使用 subprocess.call() 来调用另一个程序,但它会阻止正在执行的线程,直到该程序完成。 Is there a way to simply launch that program without waiting for return?有没有办法在不等待返回的情况下简单地启动该程序?
Use subprocess.Popen
instead of subprocess.call
:使用subprocess.Popen
而不是subprocess.call
:
process = subprocess.Popen(['foo', '-b', 'bar'])
subprocess.call
is a wrapper around subprocess.Popen
that calls communicate
to wait for the process to terminate. subprocess.call
是围绕一个包装subprocess.Popen
的呼叫communicate
等待进程终止。 See also What is the difference between subprocess.popen and subprocess.run .另请参阅subprocess.popen 和 subprocess.run 之间的区别是什么。
答案不应该是使用“close_fds”标志吗?
subprocess.Popen(cmd, stdout=None, stderr=None, stdin=None, close_fds=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.