Skip to content

Instantly share code, notes, and snippets.

@yoichi
Last active August 29, 2015 14:23
Show Gist options
  • Save yoichi/56ce718251a578a68fb0 to your computer and use it in GitHub Desktop.
Save yoichi/56ce718251a578a68fb0 to your computer and use it in GitHub Desktop.
# based on the example in https://docs.python.org/2.7/library/multiprocessing.html
from multiprocessing import Process, Queue, Manager
def f(q):
q.put('X' * 1000000)
if __name__ == '__main__':
manager = Manager()
queue = manager.Queue()
p = Process(target=f, args=(queue,))
p.start()
print("we can join process...")
p.join() # manager avoids deadlock
print("we can join process...done")
obj = queue.get()
print(obj == 'X' * 1000000)
queue = Queue()
p = Process(target=f, args=(queue,))
p.start()
print("we cannot join process...")
p.join() # this deadlocks
print("we cannot join process...done")
obj = queue.get()
print(obj == 'X' * 1000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment