mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
bpo-38377: Add support.skip_if_broken_multiprocessing_synchronize() (GH-20944) (GH-20962)
On Linux, skip tests using multiprocessing if the current user cannot
create a file in /dev/shm/ directory. Add the
skip_if_broken_multiprocessing_synchronize() function to the
test.support module.
(cherry picked from commit ddbeb2f3e0
)
This commit is contained in:
parent
610a60c601
commit
b1e7361134
8 changed files with 41 additions and 12 deletions
|
@ -33,7 +33,7 @@ from test.support import socket_helper
|
||||||
# Skip tests if _multiprocessing wasn't built.
|
# Skip tests if _multiprocessing wasn't built.
|
||||||
_multiprocessing = test.support.import_module('_multiprocessing')
|
_multiprocessing = test.support.import_module('_multiprocessing')
|
||||||
# Skip tests if sem_open implementation is broken.
|
# Skip tests if sem_open implementation is broken.
|
||||||
test.support.import_module('multiprocessing.synchronize')
|
support.skip_if_broken_multiprocessing_synchronize()
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import multiprocessing.connection
|
import multiprocessing.connection
|
||||||
|
|
|
@ -3168,3 +3168,26 @@ def save_restore_warnings_filters():
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
warnings.filters[:] = old_filters
|
warnings.filters[:] = old_filters
|
||||||
|
|
||||||
|
|
||||||
|
def skip_if_broken_multiprocessing_synchronize():
|
||||||
|
"""
|
||||||
|
Skip tests if the multiprocessing.synchronize module is missing, if there
|
||||||
|
is no available semaphore implementation, or if creating a lock raises an
|
||||||
|
OSError.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Skip tests if the _multiprocessing extension is missing.
|
||||||
|
import_module('_multiprocessing')
|
||||||
|
|
||||||
|
# Skip tests if there is no available semaphore implementation:
|
||||||
|
# multiprocessing.synchronize requires _multiprocessing.SemLock.
|
||||||
|
synchronize = import_module('multiprocessing.synchronize')
|
||||||
|
|
||||||
|
try:
|
||||||
|
# bpo-38377: On Linux, creating a semaphore is the current user
|
||||||
|
# does not have the permission to create a file in /dev/shm.
|
||||||
|
# Create a semaphore to check permissions.
|
||||||
|
synchronize.Lock(ctx=None)
|
||||||
|
except OSError as exc:
|
||||||
|
raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")
|
||||||
|
|
|
@ -2672,10 +2672,10 @@ class GetEventLoopTestsMixin:
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
|
|
||||||
def test_get_event_loop_new_process(self):
|
def test_get_event_loop_new_process(self):
|
||||||
# Issue bpo-32126: The multiprocessing module used by
|
# bpo-32126: The multiprocessing module used by
|
||||||
# ProcessPoolExecutor is not functional when the
|
# ProcessPoolExecutor is not functional when the
|
||||||
# multiprocessing.synchronize module cannot be imported.
|
# multiprocessing.synchronize module cannot be imported.
|
||||||
support.import_module('multiprocessing.synchronize')
|
support.skip_if_broken_multiprocessing_synchronize()
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
pool = concurrent.futures.ProcessPoolExecutor()
|
pool = concurrent.futures.ProcessPoolExecutor()
|
||||||
|
|
|
@ -3,7 +3,7 @@ from test import support
|
||||||
# Skip tests if _multiprocessing wasn't built.
|
# Skip tests if _multiprocessing wasn't built.
|
||||||
support.import_module('_multiprocessing')
|
support.import_module('_multiprocessing')
|
||||||
# Skip tests if sem_open implementation is broken.
|
# Skip tests if sem_open implementation is broken.
|
||||||
support.import_module('multiprocessing.synchronize')
|
support.skip_if_broken_multiprocessing_synchronize()
|
||||||
|
|
||||||
from test.support import hashlib_helper
|
from test.support import hashlib_helper
|
||||||
from test.support.script_helper import assert_python_ok
|
from test.support.script_helper import assert_python_ok
|
||||||
|
|
|
@ -3629,9 +3629,9 @@ if hasattr(logging.handlers, 'QueueListener'):
|
||||||
|
|
||||||
@patch.object(logging.handlers.QueueListener, 'handle')
|
@patch.object(logging.handlers.QueueListener, 'handle')
|
||||||
def test_handle_called_with_mp_queue(self, mock_handle):
|
def test_handle_called_with_mp_queue(self, mock_handle):
|
||||||
# Issue 28668: The multiprocessing (mp) module is not functional
|
# bpo-28668: The multiprocessing (mp) module is not functional
|
||||||
# when the mp.synchronize module cannot be imported.
|
# when the mp.synchronize module cannot be imported.
|
||||||
support.import_module('multiprocessing.synchronize')
|
support.skip_if_broken_multiprocessing_synchronize()
|
||||||
for i in range(self.repeat):
|
for i in range(self.repeat):
|
||||||
log_queue = multiprocessing.Queue()
|
log_queue = multiprocessing.Queue()
|
||||||
self.setup_and_log(log_queue, '%s_%s' % (self.id(), i))
|
self.setup_and_log(log_queue, '%s_%s' % (self.id(), i))
|
||||||
|
@ -3655,9 +3655,9 @@ if hasattr(logging.handlers, 'QueueListener'):
|
||||||
indicates that messages were not registered on the queue until
|
indicates that messages were not registered on the queue until
|
||||||
_after_ the QueueListener stopped.
|
_after_ the QueueListener stopped.
|
||||||
"""
|
"""
|
||||||
# Issue 28668: The multiprocessing (mp) module is not functional
|
# bpo-28668: The multiprocessing (mp) module is not functional
|
||||||
# when the mp.synchronize module cannot be imported.
|
# when the mp.synchronize module cannot be imported.
|
||||||
support.import_module('multiprocessing.synchronize')
|
support.skip_if_broken_multiprocessing_synchronize()
|
||||||
for i in range(self.repeat):
|
for i in range(self.repeat):
|
||||||
queue = multiprocessing.Queue()
|
queue = multiprocessing.Queue()
|
||||||
self.setup_and_log(queue, '%s_%s' %(self.id(), i))
|
self.setup_and_log(queue, '%s_%s' %(self.id(), i))
|
||||||
|
|
|
@ -23,7 +23,7 @@ import multiprocessing
|
||||||
AVAILABLE_START_METHODS = set(multiprocessing.get_all_start_methods())
|
AVAILABLE_START_METHODS = set(multiprocessing.get_all_start_methods())
|
||||||
|
|
||||||
# Issue #22332: Skip tests if sem_open implementation is broken.
|
# Issue #22332: Skip tests if sem_open implementation is broken.
|
||||||
support.import_module('multiprocessing.synchronize')
|
support.skip_if_broken_multiprocessing_synchronize()
|
||||||
|
|
||||||
verbose = support.verbose
|
verbose = support.verbose
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,8 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from test.support import (captured_stdout, captured_stderr, requires_zlib,
|
from test.support import (captured_stdout, captured_stderr, requires_zlib,
|
||||||
can_symlink, EnvironmentVarGuard, rmtree,
|
can_symlink, EnvironmentVarGuard, rmtree,
|
||||||
import_module)
|
import_module,
|
||||||
|
skip_if_broken_multiprocessing_synchronize)
|
||||||
import unittest
|
import unittest
|
||||||
import venv
|
import venv
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
@ -357,10 +358,11 @@ class BasicTest(BaseTest):
|
||||||
"""
|
"""
|
||||||
Test that the multiprocessing is able to spawn.
|
Test that the multiprocessing is able to spawn.
|
||||||
"""
|
"""
|
||||||
# Issue bpo-36342: Instantiation of a Pool object imports the
|
# bpo-36342: Instantiation of a Pool object imports the
|
||||||
# multiprocessing.synchronize module. Skip the test if this module
|
# multiprocessing.synchronize module. Skip the test if this module
|
||||||
# cannot be imported.
|
# cannot be imported.
|
||||||
import_module('multiprocessing.synchronize')
|
skip_if_broken_multiprocessing_synchronize()
|
||||||
|
|
||||||
rmtree(self.env_dir)
|
rmtree(self.env_dir)
|
||||||
self.run_with_capture(venv.create, self.env_dir)
|
self.run_with_capture(venv.create, self.env_dir)
|
||||||
envpy = os.path.join(os.path.realpath(self.env_dir),
|
envpy = os.path.join(os.path.realpath(self.env_dir),
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
On Linux, skip tests using multiprocessing if the current user cannot create
|
||||||
|
a file in ``/dev/shm/`` directory. Add the
|
||||||
|
:func:`~test.support.skip_if_broken_multiprocessing_synchronize` function to
|
||||||
|
the :mod:`test.support` module.
|
Loading…
Add table
Add a link
Reference in a new issue