Created
July 30, 2017 14:06
-
-
Save swshan/354fbda44756654e719cfa2ff64cba0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#coding=utf-8 | |
import multiprocessing | |
import time | |
def proc1(pipe): | |
while True: | |
for i in range(10000): | |
print 'send %s' % i | |
pipe.send(i) | |
time.sleep(1) | |
def proc2(pipe): | |
while True: | |
print 'proc2 recv', pipe.recv() | |
time.sleep(1) | |
def proc3(pipe): | |
while True: | |
print 'proc3 recv', pipe().recv() | |
time.sleep(1) | |
if __name__ == '__main__': | |
pipe = multiprocessing.Pipe() | |
print pipe | |
p1 = multiprocessing.Process(target=proc1, args=(pipe[0],)) | |
p2 = multiprocessing.Process(target=proc2, args=(pipe[1],)) | |
p1.start() | |
p2.start() | |
p1.join() | |
p2.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment