Skip to content

Instantly share code, notes, and snippets.

@swshan
Created July 30, 2017 14:06
Show Gist options
  • Save swshan/354fbda44756654e719cfa2ff64cba0a to your computer and use it in GitHub Desktop.
Save swshan/354fbda44756654e719cfa2ff64cba0a to your computer and use it in GitHub Desktop.
#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