threading.Event wait function not signaled when subclassing Process class

Posted by user1313404 on Stack Overflow See other posts from Stack Overflow or by user1313404
Published on 2012-04-04T16:59:42Z Indexed on 2012/04/04 17:29 UTC
Read the original article Hit count: 188

For following code never gets past the wait function in run. I'm certain I'm doing something ridiculously stupid, but since I'm not smart enough to figure out what, I'm asking. Any help is appreciated. Here is the code:

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

© Stack Overflow or respective owner

Related posts about python

Related posts about multithreading