Created
June 27, 2015 17:42
-
-
Save MarkLavrynenko/02711dc9c16242afd96f to your computer and use it in GitHub Desktop.
Interesting thing with Pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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