[英]Running two Python 2.7 scripts simultaneously
I have two Python scripts, one of which is try.py
which contains this: 我有两个Python脚本,其中一个是try.py
,其中包含以下内容:
import os
os.system('python hello.py')
print "over"
This script calls another script by name hello.py
, and hello.py
contains: 该脚本通过名称hello.py
调用另一个脚本,并且hello.py
包含:
import time
var = 1
while (var < 60):
var = var + 1
print var
time.sleep(0.5)
There are two problems which I am facing: 我面临两个问题:
One is I want to run both the scripts simultaneously. 一种是我想同时运行两个脚本。
but in my case my try.py
script continues to run after hello.py
is finished running. 但就我而言,我的try.py
脚本在hello.py
完成运行后继续运行。
You might want to use subprocess.Popen()
: 您可能要使用subprocess.Popen()
:
import subprocess
p = subprocess.Popen(['python', 'hello.py'])
print "over"
p.wait()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.