Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX safe queue compat for python3.9 #265

Closed
wants to merge 2 commits into from
Closed

Conversation

tomMoral
Copy link
Collaborator

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
Collaborator

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
Collaborator

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.

None yet

2 participants