Skip to content

Commit d46d3f2

Browse files
authored
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.
1 parent dbb6e22 commit d46d3f2

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Lib/multiprocessing/synchronize.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,21 @@
2121
from . import process
2222
from . import util
2323

24-
# Try to import the mp.synchronize module cleanly, if it fails
25-
# raise ImportError for platforms lacking a working sem_open implementation.
26-
# See issue 3770
24+
# TODO: Do any platforms still lack a functioning sem_open?
2725
try:
2826
from _multiprocessing import SemLock, sem_unlink
29-
except (ImportError):
27+
except ImportError:
3028
raise ImportError("This platform lacks a functioning sem_open" +
31-
" implementation, therefore, the required" +
32-
" synchronization primitives needed will not" +
33-
" function, see issue 3770.")
29+
" implementation. https://github.com/python/cpython/issues/48020.")
3430

3531
#
3632
# Constants
3733
#
3834

39-
RECURSIVE_MUTEX, SEMAPHORE = list(range(2))
35+
# These match the enum in Modules/_multiprocessing/semaphore.c
36+
RECURSIVE_MUTEX = 0
37+
SEMAPHORE = 1
38+
4039
SEM_VALUE_MAX = _multiprocessing.SemLock.SEM_VALUE_MAX
4140

4241
#

Modules/_multiprocessing/semaphore.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#ifdef HAVE_MP_SEMAPHORE
1717

18+
// These match the values in Lib/multiprocessing/synchronize.py
1819
enum { RECURSIVE_MUTEX, SEMAPHORE };
1920

2021
typedef struct {

0 commit comments

Comments
 (0)