[英]Python subprocess.popen() without waiting
I'm using Python 3.4.2 on Windows. 我在Windows上使用Python 3.4.2。 In script1.py I'm doing this:
在script1.py我这样做:
myProc = subprocess.Popen([sys.executable, "script2.py", "argument"])
myProc.communicate()
it works and call script2.py . 它工作并调用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.
问题是在script2.py中有一个无限循环(必须有)并且script1.py正在等待script2.py完成。 How can I tell to script1.py to just call script2.py and don't wait for the process to finish?
如何告诉script1.py只调用script2.py并且不要等待进程完成?
Just don't call myProc.communicate()
if you don't want to wait. 如果你不想等,请不要调用
myProc.communicate()
。 subprocess.Popen
will start the process. subprocess.Popen
将启动该进程。
Call the script in another window. 在另一个窗口中调用脚本。
myProc = subprocess.Popen(["start", sys.executable, "script2.py", "argument"])
myProc.communicate()
start
is a windows shell function that runs a program separately, allowing the current one to continue its process. start
是一个单独运行程序的Windows shell函数,允许当前程序继续其进程。 I haven't tested this as I've no access to a Windows OS, but The linux equivalent ( nohup
) works as required. 我没有测试过这个,因为我无法访问Windows操作系统,但Linux等效(
nohup
)可以按要求工作。
If you need fine control over what happens with script2.py, refer to the multiprocessing
module here . 如果您需要对script2.py的操作进行精确控制,请参阅此处的
multiprocessing
模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.