Skip to content

Conversation

@tomMoral
Copy link
Contributor

Fix for #251 .

The change was on the after_fork/reset functionality.

$ git diff 3.8 3.9 -- Lib/multiprocessing/queues.py
diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py
index d112db2cd9..a290181487 100644
--- a/Lib/multiprocessing/queues.py
+++ b/Lib/multiprocessing/queues.py
@@ -14,6 +14,7 @@ import os
 import threading
 import collections
 import time
+import types
 import weakref
 import errno
 
@@ -48,8 +49,7 @@ class Queue(object):
         self._sem = ctx.BoundedSemaphore(maxsize)
         # For use by concurrent.futures
         self._ignore_epipe = False
-
-        self._after_fork()
+        self._reset()
 
         if sys.platform != 'win32':
             register_after_fork(self, Queue._after_fork)
@@ -62,11 +62,17 @@ class Queue(object):
     def __setstate__(self, state):
         (self._ignore_epipe, self._maxsize, self._reader, self._writer,
          self._rlock, self._wlock, self._sem, self._opid) = state
-        self._after_fork()
+        self._reset()
 
     def _after_fork(self):
         debug('Queue._after_fork()')
-        self._notempty = threading.Condition(threading.Lock())
+        self._reset(after_fork=True)
+
+    def _reset(self, after_fork=False):
+        if after_fork:
+            self._notempty._at_fork_reinit()
+        else:
+            self._notempty = threading.Condition(threading.Lock())
         self._buffer = collections.deque()
         self._thread = None
         self._jointhread = None

@ogrisel
Copy link
Contributor

ogrisel commented Sep 10, 2020

The failure on older Python versions is probably caused by #260.

@ogrisel ogrisel closed this Sep 10, 2020
@ogrisel ogrisel deleted the FIX_safe_queue branch September 10, 2020 09:07
@ogrisel
Copy link
Contributor

ogrisel commented Sep 10, 2020

The commits of this PR have been included in #250 directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants