python multiprocessing member variable not set

Posted by Jake on Stack Overflow See other posts from Stack Overflow or by Jake
Published on 2010-04-21T19:11:17Z Indexed on 2010/04/21 19:13 UTC
Read the original article Hit count: 231

Filed under:
|

In the following script, I get the "stop message received" output but the process never ends. Why is that? Is there another way to end a process besides terminate or os.kill that is along these lines?

from multiprocessing import Process
from time import sleep

class Test(Process):
    def __init__(self):
        Process.__init__(self)
        self.stop = False

    def run(self):
        while self.stop == False:
            print "running"
            sleep(1.0)

    def end(self):
        print "stop message received"
        self.stop = True

if __name__ == "__main__":
    test = Test()
    test.start()
    sleep(1.0)
    test.end()
    test.join()

© Stack Overflow or respective owner

Related posts about python

Related posts about multiprocessing