因为下面的代码永远不会超过运行中的等待函数。我确定我在做一些非常愚蠢的事情,但是由于我不够聪明,无法弄清楚是什么,所以我在问。任何帮助表示赞赏。这是代码:
import threading
import multiprocessing
from multiprocessing import Process
class SomeClass(Process):
def __init__(self):
Process.__init__(self)
self.event = threading.Event()
self.event.clear()
def continueExec(self):
print multiprocessing.current_process().name
print self
print "Set:" + str(self.event.is_set())
self.event.set()
print "Set:" + str(self.event.is_set())
def run(self):
print "I'm running with it"
print multiprocessing.current_process().name
self.event.wait()
print "I'm further than I was"
print multiprocessing.current_process().name
self.event.clear()
def main():
s_list = []
for t in range(3):
s = SomeClass()
print "s:" + str(s)
s_list.append(s)
s.start()
raw_input("Press enter to send signal")
for t in range(3):
print "s_list["+str(t)+"]:" + str(s_list[t])
s_list[t].continueExec()
raw_input("Press enter to send signal")
for t in range(3):
s_list[t].join()
print "All Done"
if __name__ == "__main__":
main()