bpo-38377: Fix skip_if_broken_multiprocessing_synchronize() on macOS (GH-20984)

skip_if_broken_multiprocessing_synchronize() only attempts for create
a semaphore on Linux to fix multiprocessing
test_resource_tracker_reused() on macOS.
This commit is contained in:
Victor Stinner 2020-06-19 18:01:20 +02:00 committed by GitHub
parent ec68918795
commit 3358da4054
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1962,7 +1962,7 @@ def skip_if_broken_multiprocessing_synchronize():
""" """
Skip tests if the multiprocessing.synchronize module is missing, if there Skip tests if the multiprocessing.synchronize module is missing, if there
is no available semaphore implementation, or if creating a lock raises an is no available semaphore implementation, or if creating a lock raises an
OSError. OSError (on Linux only).
""" """
# Skip tests if the _multiprocessing extension is missing. # Skip tests if the _multiprocessing extension is missing.
@ -1972,10 +1972,11 @@ def skip_if_broken_multiprocessing_synchronize():
# multiprocessing.synchronize requires _multiprocessing.SemLock. # multiprocessing.synchronize requires _multiprocessing.SemLock.
synchronize = import_module('multiprocessing.synchronize') synchronize = import_module('multiprocessing.synchronize')
try: if sys.platform == "linux":
# bpo-38377: On Linux, creating a semaphore is the current user try:
# does not have the permission to create a file in /dev/shm. # bpo-38377: On Linux, creating a semaphore fails with OSError
# Create a semaphore to check permissions. # if the current user does not have the permission to create
synchronize.Lock(ctx=None) # a file in /dev/shm/ directory.
except OSError as exc: synchronize.Lock(ctx=None)
raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}") except OSError as exc:
raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")