Last active
January 4, 2016 04:39
-
-
Save jbking/8570251 to your computer and use it in GitHub Desktop.
The object for IPC couldn't be passed to another process which is able to pass to another goroutine in golang. Interchanging such object in golang is not actual IPC, but its design could be similar, for similar usage.
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
% python passing_queue_like_go.py | |
Traceback (most recent call last): | |
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 266 | |
, in _feed | |
send(obj) | |
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 77, | |
in __getstate__ | |
assert_spawning(self) | |
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/forking.py", line 52 | |
, in assert_spawning | |
' through inheritance' % type(self).__name__ | |
RuntimeError: Queue objects should only be shared between processes through inheritance |
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 Process, Queue | |
def passing(i, q, qq): | |
qo = q.get() | |
qq.put(qo) | |
qo.put(i) | |
sq = q = Queue() | |
for i in range(3): | |
qq = Queue() | |
Process(target=passing, args=(i, q, qq)).start() | |
q = qq | |
eq = Queue() | |
sq.put(eq) | |
eq_ = qq.get() | |
while True: | |
try: | |
print(eq_.get(False)) | |
except Queue.Empty: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment