[issue40402] Race condition in multiprocessing/connection.py: broken handle

2020-04-29 Thread STINNER Victor


STINNER Victor  added the comment:

See also bpo-39995: race condition in concurrent.futures. More specific to 
_ThreadWakeup class, but with similar symptoms.

--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40402] Race condition in multiprocessing/connection.py: broken handle

2020-04-29 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
keywords: +patch
pull_requests: +19113
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/19790

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40402] Race condition in multiprocessing/connection.py: broken handle

2020-04-27 Thread Antoine Pitrou


Antoine Pitrou  added the comment:

I don't know if a try..except block is the best solution, but feel free to 
submit a PR and we can iterate on that :-)

--
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40402] Race condition in multiprocessing/connection.py: broken handle

2020-04-27 Thread Rémi Lapeyre

Rémi Lapeyre  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 "", line 10, in 
/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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com