Last active
August 29, 2015 14:23
-
-
Save yoichi/56ce718251a578a68fb0 to your computer and use it in GitHub Desktop.
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
# 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