[issue39995] test_concurrent_futures: ProcessPoolSpawnExecutorDeadlockTest.test_crash() fails with OSError: [Errno 9] Bad file descriptor

Antoine Pitrou report at bugs.python.org
Tue Apr 28 04:08:36 EDT 2020


Antoine Pitrou <solipsis at pitrou.net> added the comment:

How about the following (untested):

diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
index 8e9b69a8f0..c0c2eb3032 100644
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -66,23 +66,29 @@ _global_shutdown = False
 
 class _ThreadWakeup:
     def __init__(self):
-        self._closed = False
         self._reader, self._writer = mp.Pipe(duplex=False)
 
     def close(self):
-        if not self._closed:
-            self._closed = True
-            self._writer.close()
-            self._reader.close()
+        r, w = self._reader, self._writer
+        self._reader = self._writer = None
+        if r is not None:
+            r.close()
+            w.close()
 
     def wakeup(self):
-        if not self._closed:
+        try:
             self._writer.send_bytes(b"")
+        except AttributeError:
+            # Closed
+            pass
 
     def clear(self):
-        if not self._closed:
+        try:
             while self._reader.poll():
                 self._reader.recv_bytes()
+        except AttributeError:
+            # Closed
+            pass
 
 
 def _python_exit():

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39995>
_______________________________________


More information about the Python-bugs-list mailing list