https://github.com/python/cpython/commit/d46d3f2ec783004f0927c9f5e6211a570360cf3b
commit: d46d3f2ec783004f0927c9f5e6211a570360cf3b
branch: main
author: Gregory P. Smith <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-11-07T00:06:14-08:00
summary:
Cleanup multiprocessing comment and unusual import error message (#126532)
Define constants as constants rather than calling `list(range(2))`.
Explain which values must remain in sync via comments.
files:
M Lib/multiprocessing/synchronize.py
M Modules/_multiprocessing/semaphore.c
diff --git a/Lib/multiprocessing/synchronize.py
b/Lib/multiprocessing/synchronize.py
index 3ccbfe311c71f3..1917a8bd51dcab 100644
--- a/Lib/multiprocessing/synchronize.py
+++ b/Lib/multiprocessing/synchronize.py
@@ -21,22 +21,21 @@
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
#
diff --git a/Modules/_multiprocessing/semaphore.c
b/Modules/_multiprocessing/semaphore.c
index 4de4ee6c78fbd1..9eef7c25636899 100644
--- a/Modules/_multiprocessing/semaphore.c
+++ b/Modules/_multiprocessing/semaphore.c
@@ -15,6 +15,7 @@
#ifdef HAVE_MP_SEMAPHORE
+// These match the values in Lib/multiprocessing/synchronize.py
enum { RECURSIVE_MUTEX, SEMAPHORE };
typedef struct {
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]