Skip to content

Instantly share code, notes, and snippets.

@MarkLavrynenko
Created June 27, 2015 17:42
Show Gist options
  • Save MarkLavrynenko/02711dc9c16242afd96f to your computer and use it in GitHub Desktop.
Save MarkLavrynenko/02711dc9c16242afd96f to your computer and use it in GitHub Desktop.
Interesting thing with Pipe
from multiprocessing import Pool, Pipe, Process
def work(process_name, pipe):
while True:
print("%s Start w8!" % process_name)
data = pipe.recv()
print("%s You sent %s" % (process_name, data))
if __name__ == "__main__":
parent, child = Pipe()
p1 = Process(target=work, args=("P1", child,))
p1.start()
p2 = Process(target=work, args=("P2", child,))
p2.start()
while True:
try:
data = raw_input()
parent.send(data)
except KeyboardInterrupt:
print("On KeyboardInterrupt")
child.close()
parent.close()
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment