Python subprocess.popen()无需等待 [英] Python subprocess.popen() without waiting

查看:195
本文介绍了Python subprocess.popen()无需等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上使用Python 3.4.2.在script1.py中,我正在这样做:

I'm using Python 3.4.2 on Windows. In script1.py I'm doing this:

myProc = subprocess.Popen([sys.executable, "script2.py", "argument"])
myProc.communicate()

它可以工作并调用script2.py. 问题是在script2.py中存在一个无限循环(必须存在),并且script1.py正在等待script2.py完成.我该如何告诉script1.py仅调用script2.py,而不必等待该过程完成?

it works and call script2.py . The problem is that in script2.py there is a infinite loop (there must be) and the script1.py is waiting for script2.py to finish. How can I tell to script1.py to just call script2.py and don't wait for the process to finish?

推荐答案

如果不想等待,请不要调用myProc.communicate(). subprocess.Popen将开始该过程.

Just don't call myProc.communicate() if you don't want to wait. subprocess.Popen will start the process.

这篇关于Python subprocess.popen()无需等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆