Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/concurrent/futures/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,8 @@ def _check_system_limits():
raise NotImplementedError(_system_limited)
try:
nsems_max = os.sysconf("SC_SEM_NSEMS_MAX")
except (AttributeError, ValueError):
# sysconf not available or setting not available
except (AttributeError, ValueError, OSError):
# sysconf not available, setting not available, or read denied
return
if nsems_max == -1:
# indetermined limit, assume that limit is determined
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_concurrent_futures/test_process_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ def test_max_workers_too_large(self):
"max_workers must be <= 61"):
futures.ProcessPoolExecutor(max_workers=62)

@unittest.skipUnless(hasattr(os, 'sysconf'), 'requires os.sysconf')
def test_sysconf_permission_error(self):
# Issue 155912: ProcessPoolExecutor should handle PermissionError
# from os.sysconf("SC_SEM_NSEMS_MAX") when running under a strict sandbox.
def mock_sysconf(name):
if name == "SC_SEM_NSEMS_MAX":
raise PermissionError(1, "Operation not permitted")
# If it asks for something else, let the real one handle it
# (though normally _check_system_limits only asks for SC_SEM_NSEMS_MAX)
return os_sysconf_orig(name)

os_sysconf_orig = os.sysconf
with unittest.mock.patch('os.sysconf', side_effect=mock_sysconf):
# Should construct without raising PermissionError
with futures.ProcessPoolExecutor(max_workers=1) as executor:
pass


@warnings_helper.ignore_fork_in_thread_deprecation_warnings()
def test_killed_child(self):
# When a child process is abruptly terminated, the whole pool gets
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle :exc:`PermissionError` from :func:`os.sysconf` in ``concurrent.futures.ProcessPoolExecutor`` when running under a strict sandbox.
Loading