Python multiprocessing pipe will not recv() properly in PyDev, works fine anywhere else

纵饮孤独 提交于 2019-12-13 18:00:46

问题


This is from another question I had. I discovered that this error only occurs in PyDev. If I run the code from the command line or from IDLE, the proper output is produced. In PyDev, nothing happens:

This is for Python 3.2.2, Eclipse 3.7.2:

from multiprocessing import Pipe, Process

def f(r):
    print(r.recv())

if __name__ == '__main__':
    q, r = Pipe()
    p = Process(target=f, args=(r,))
    p.start()
    q.send([42, None, 'hello'])
    p.join()

The main thread creates a new Process, p, and sends r, a bidirectional connection object, to function f(). When process p is started, I expect r.recv() to block (which, as far as I understand, means that this process will wait indefinitely until something comes through the pipe) until the main process sends some objects through with q.send.

Then p.join() should make the main process wait until p has run its course.

But nothing whatsoever happens. If I add a print statement to f(), nothing happens there, either, as if f() never even runs and p.start() is nonfunctional.

Can you explain why this won't work in PyDev and what might be fixed?

来源:https://stackoverflow.com/questions/10464946/python-multiprocessing-pipe-will-not-recv-properly-in-pydev-works-fine-anywhe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!