繁体   English   中英

终止长时间运行的脚本?

[英]terminate long running script?

我有2个脚本。

main.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()

哪个调用test.py

import time

while True:
    print 'hello'
    time.sleep(1)

延迟30秒后,我想终止test.py。
我正在使用python 2.4.2。 是否可以通过事件生成来执行此操作?对此代码或任何其他替代模块的任何建议都可以执行。

更好的选择是使用subprocess模块( https://docs.python.org/2/library/subprocess.html )启动外部流程。 另请参阅此帖子: 如何终止用shell = True启动的python子进程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM