]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Cleanup multiprocessing comment and unusual import error message (#126532)
authorGregory P. Smith <greg@krypto.org>
Thu, 7 Nov 2024 08:06:14 +0000 (00:06 -0800)
committerGitHub <noreply@github.com>
Thu, 7 Nov 2024 08:06:14 +0000 (00:06 -0800)
Define constants as constants rather than calling `list(range(2))`.
Explain which values must remain in sync via comments.

Lib/multiprocessing/synchronize.py
Modules/_multiprocessing/semaphore.c

index 3ccbfe311c71f37e799eb8444af84677881116b8..1917a8bd51dcabb5bdc753416b133136333ba117 100644 (file)
@@ -21,22 +21,21 @@ from . import context
 from . import process
 from . import util
 
-# Try to import the mp.synchronize module cleanly, if it fails
-# raise ImportError for platforms lacking a working sem_open implementation.
-# See issue 3770
+# TODO: Do any platforms still lack a functioning sem_open?
 try:
     from _multiprocessing import SemLock, sem_unlink
-except (ImportError):
+except ImportError:
     raise ImportError("This platform lacks a functioning sem_open" +
-                      " implementation, therefore, the required" +
-                      " synchronization primitives needed will not" +
-                      " function, see issue 3770.")
+                      " implementation. https://github.com/python/cpython/issues/48020.")
 
 #
 # Constants
 #
 
-RECURSIVE_MUTEX, SEMAPHORE = list(range(2))
+# These match the enum in Modules/_multiprocessing/semaphore.c
+RECURSIVE_MUTEX = 0
+SEMAPHORE = 1
+
 SEM_VALUE_MAX = _multiprocessing.SemLock.SEM_VALUE_MAX
 
 #
index 4de4ee6c78fbd1dbd8c2dee91ad4482c252c21b2..9eef7c25636899caf9719e7da98a1bf06275962f 100644 (file)
@@ -15,6 +15,7 @@
 
 #ifdef HAVE_MP_SEMAPHORE
 
+// These match the values in Lib/multiprocessing/synchronize.py
 enum { RECURSIVE_MUTEX, SEMAPHORE };
 
 typedef struct {