FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-155717: Fix importing multiprocessing with no usable temp directory by fedonman · Pull Request #158410 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 4 additions & 1 deletion Lib/multiprocessing/util.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ def _has_writeable_tempdir():
#
# See: https://github.com/python/cpython/issues/155717.

path = _get_base_temp_dir()
try:
path = _get_base_temp_dir()
except OSError:
return False
if path is None:
return False

Expand Down
32 changes: 32 additions & 0 deletions Lib/test/_test_multiprocessing.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6514,6 +6514,38 @@ def test_forkserver_requires_writeable_tempdir(self, mode):
_, out, err = script_helper.assert_python_ok('-c', cmd, TMPDIR=TMPDIR)
self.assertEqual(out.decode().strip(), "spawn")

@unittest.skipIf(os.name == "nt", "requires POSIX")
@support.requires_non_root_user
def test_import_without_usable_tempdir(self):
# Importing multiprocessing must not fail when tempfile finds no
# usable temporary directory at all, and the default start method
# must then be 'spawn'.
#
# See https://github.com/python/cpython/issues/155717.

cmd = '''if 1:
import os, tempfile
# Make TMPDIR the only candidate, so that tempfile.gettempdir()
# raises FileNotFoundError instead of falling back to /tmp.
tempfile._candidate_tempdir_list = lambda: [os.environ["TMPDIR"]]
try:
tempfile.gettempdir()
except FileNotFoundError:
pass
else:
raise AssertionError("TMPDIR is usable")

import multiprocessing
if __name__ == "__main__":
print(multiprocessing.get_start_method())
'''

with support.os_helper.temp_dir() as root:
TMPDIR = pathlib.Path(root, "TMPDIR")
TMPDIR.mkdir(mode=os.R_OK | os.X_OK)
_, out, err = script_helper.assert_python_ok('-c', cmd, TMPDIR=TMPDIR)
self.assertEqual(out.decode().strip(), "spawn")


@unittest.skipIf(sys.platform == "win32",
"test semantics don't make sense on Windows")
Expand Down
Loading

Back | FazBrowse Home | New Git URL