Message339847
The docs for https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue.close read:
> Indicate that no more data will be put on this queue by the current process. The background thread will quit once it has flushed all buffered data to the pipe. This is called automatically when the queue is garbage collected.
From this text it seems to me as though the queue should be used as follows:
import contextlib
import multiprocessing
def worker(q):
with contextlib.closing(q):
q.put_nowait('hello')
def controller():
q = multiprocessing.Queue()
q.close() # no more 'put's from this process
p = multiprocessing.Process(target=worker, args=(q, ))
p.start()
assert q.get() == 'hello'
p.join()
assert p.exitcode == 0
print('OK!')
if __name__ == '__main__':
controller()
however I get this:
Traceback (most recent call last):
File "controller.py", line 22, in <module>
controller()
File "controller.py", line 15, in controller
assert q.get() == 'hello'
File "/usr/lib/python3.7/multiprocessing/queues.py", line 94, in get
res = self._recv_bytes()
File "/usr/lib/python3.7/multiprocessing/connection.py", line 212, in recv_bytes
self._check_closed()
File "/usr/lib/python3.7/multiprocessing/connection.py", line 136, in _check_closed
raise OSError("handle is closed")
OSError: handle is closed |
|
Date |
User |
Action |
Args |
2019-04-10 10:42:31 | graingert | set | recipients:
+ graingert |
2019-04-10 10:42:31 | graingert | set | messageid: <1554892951.92.0.81637767288.issue36586@roundup.psfhosted.org> |
2019-04-10 10:42:31 | graingert | link | issue36586 messages |
2019-04-10 10:42:31 | graingert | create | |
|