【发布时间】:2010-03-15 01:48:31
【问题描述】:
代码优先:
'''this is main structure of my program'''
from twisted.web import http
from twisted.protocols import basic
import threading
threadstop = False #thread trigger,to be done
class MyThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.start()
def run(self):
while True:
if threadstop:
return
dosomething()
'''def some function'''
if __name__ == '__main__':
from twisted.internet import reactor
t = MyThread()
reactor.listenTCP(serverport,myHttpFactory())
reactor.run()
作为我的第一个多线程程序,我很高兴它能按预期工作。但现在我发现我无法控制它。如果我在前面运行,Control+C只能停止主进程,在processlist中还是可以找到的;如果我在后台运行它,我必须使用kill -9 pid 来停止它。而且我想知道除了kill -9之外,有没有办法通过触发变量来控制子线程进程,或者有更好的方法来停止整个进程。
【问题讨论】:
标签: python multithreading twisted