Skip to content

Instantly share code, notes, and snippets.

@jbking
Last active January 4, 2016 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbking/8570251 to your computer and use it in GitHub Desktop.
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.
% 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
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