Michael David Watson
Michael David Watson

Reputation: 3071

Multiprocessing pipes on windows with python

Does Windows support multithreading.pipes()? If yes, then what is wrong with this code? Do I need to be using reduction? The code hangs on p2.recv() and I get a RuntimeError when run from the command line.

import multiprocessing
def ProcessCreator(pipe):
    pipe.send("hello from other process")

p1, p2 = multiprocessing.Pipe()
proc = multiprocessing.Process(target = ProcessCreator, args = (p2,))
proc.start()
print p1.recv()

if __name__ == "__main__":
    multiprocessing.freeze_support()

Upvotes: 0

Views: 1587

Answers (1)

eshizhan
eshizhan

Reputation: 4635

You need put pipe code into if __name__ == '__main__' part.(Why?) And change p2.recv to p1.recv

import multiprocessing
def ProcessCreator(pipe):
    pipe.send("hello from other process")

if __name__ == "__main__":
    multiprocessing.freeze_support()
    p1, p2 = multiprocessing.Pipe()
    proc = multiprocessing.Process(target = ProcessCreator, args = (p2,))
    proc.start()
    print p1.recv()

Upvotes: 2

Related Questions