我有两个剧本。你知道吗
主.py
import threading
import time
import os
exitflag = 0
class Testrun(threading.Thread):
def __init__(self,threadID,name,delay):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.delay = delay
def run(self):
print 'launching test '+self.name
launch_test(self.name,self.delay)
print 'exitiing test '+self.name
def launch_test(threadname,delay):
os.system('test.py')
if exitflag ==1:
threadname.exit()
thread = Testrun(1,'test',10)
thread.start()
它叫测试.py:
import time
while True:
print 'hello'
time.sleep(1)
延迟30秒后,我想终止测试.py
我使用的是python2.4.2。
有什么方法可以通过事件生成来实现这一点吗
对此代码或任何其他替代模块的任何建议都可以。你知道吗
更好的选择是使用
subprocess
模块(https://docs.python.org/2/library/subprocess.html)启动外部进程。也可以看这篇文章:How to terminate a python subprocess launched with shell=True相关问题 更多 >
编程相关推荐