Rémi Lapeyre <[email protected]> added the comment:
A call to self._check_closed() is already present in Python 3.5
https://github.com/python/cpython/blob/3.5/Lib/multiprocessing/connection.py#L202-L206
It is possible for some issues to appear when mixing multiprocessing and
multithreading thought:
In [17]: from time import sleep
...: import multiprocessing, threading
...:
...: class Test:
...: def __reduce__(self):
...: sleep(1)
...: return (Test, ())
...:
...: parent, child = multiprocessing.Pipe()
...: threading.Thread(target=lambda: parent.send(Test())).start()
...: parent.close()
Exception in thread Thread-7:
Traceback (most recent call last):
File "/Users/remi/src/cpython/Lib/threading.py", line 950, in _bootstrap_inner
self.run()
File "/Users/remi/src/cpython/Lib/threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "<ipython-input-17-43406d743010>", line 10, in <lambda>
/Users/remi/src/cpython/venv/lib/python3.9/site-packages/prompt_toolkit/renderer.py:514:
DeprecationWarning: The explicit passing of coroutine objects to
asyncio.wait() is deprecated since Python 3.8, and scheduled for removal in
Python 3.11.
await wait(coroutines, return_when=FIRST_COMPLETED)
File "/Users/remi/src/cpython/Lib/multiprocessing/connection.py", line 211,
in send
self._send_bytes(_ForkingPickler.dumps(obj))
File "/Users/remi/src/cpython/Lib/multiprocessing/connection.py", line 416,
in _send_bytes
self._send(header + buf)
File "/Users/remi/src/cpython/Lib/multiprocessing/connection.py", line 373,
in _send
n = write(self._handle, buf)
TypeError: an integer is required (got type NoneType)
Maybe using a try-catch block could be more appropriate than the current check.
CC-ing Antoine Pitrou as he is the original author of this part in
87cf220972c9cb400ddcd577962883dcc5dca51a. If you are OK with replacing calls to
self._check_closed() by an exception block I would be happy to open a PR for
this.
----------
components: +Library (Lib)
nosy: +pitrou
title: multiprocessing/connection.py broken handle -> Race condition in
multiprocessing/connection.py: broken handle
versions: +Python 3.7, Python 3.8, Python 3.9 -Python 3.5
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40402>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com