问题
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