문제

주어진 이 버그 (Python Issue 4892) 다음과 같은 오류가 발생합니다.

>>> import multiprocessing
>>> multiprocessing.allow_connection_pickling()
>>> q = multiprocessing.Queue()
>>> p = multiprocessing.Pipe()
>>> q.put(p)
>>> q.get()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File     "/.../python2.6/multiprocessing/queues.py", line 91, in get
    res = self._recv()
TypeError: Required argument 'handle' (pos 1) not found

큐에서 연결 객체를 전달하기 위해 해결 방법을 아는 사람이 있습니까?

고맙습니다.

도움이 되었습니까?

해결책

(내가 믿는 것은) 더 나은 방법으로, 어떤 사람들이 연주 한 후 (나는 같은 문제를 겪고 있었다. 파이프를 통해 파이프를 전달하고 싶었다.)이 게시물을 발견하기 전에 :

>>> from multiprocessing import Pipe, reduction
>>> i, o = Pipe()
>>> reduced = reduction.reduce_connection(i)
>>> newi = reduced[0](*reduced[1])
>>> newi.send("hi")
>>> o.recv()
'hi'

나는 이것이 왜 이런 식으로 만들어 졌는지 전적으로 확신하지 못한다 (누군가 멀티 프로세싱의 감소 부분이 그것에 대한 것이 무엇인지에 대한 통찰력이 필요할 것입니다), 그것은 확실히 작동하며 피클 수입이 필요하지 않습니다. 그 외에는 위의 내용에 매우 가깝지만 더 간단합니다. 나는 또한 이것을 Python Bug Report에 던져서 다른 사람들이 해결 방법을 알았습니다.

다른 팁

여기에 내가 한 일은 다음과 같습니다.

# Producer
from multiprocessing.reduction import reduce_connection
from multiprocessing import Pipe

   # Producer and Consumer share the Queue we call queue
def handle(queue):
   reader, writer = Pipe()
   pickled_writer = pickle.dumps(reduce_connection(writer))
   queue.put(pickled_writer)

그리고

# Consumer
from multiprocessing.reduction import rebuild_connection

def wait_for_request():
    pickled_write = queue.get(block=True) # block=True isn't necessary, of course
    upw = pickle.loads(pickled_writer) # unpickled writer
    writer = upw[0](upw[1][0],upw[1][1],upw[1][2])

마지막 줄은 암호화되어 다음에서 나옵니다.

>>> upw
(<function rebuild_connection at 0x1005df140>,
(('/var/folders/.../pymp-VhT3wX/listener-FKMB0W',
17, False), True, True))

그것이 다른 사람을 돕기를 바랍니다. 그것은 나를 위해 잘 작동합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top