Skip to content

Commit ee42934

Browse files
committed
Fix possible "file already exists" error when running the tests in parallel.
This is a perfect example of LBYL going wrong: that code could be executed by several workers in parallel, and os.mkdir() attempted on the same path by multiple processes.
1 parent 1d827ff commit ee42934

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/test/regrtest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
import io
163163
import sys
164164
import time
165+
import errno
165166
import traceback
166167
import warnings
167168
import unittest
@@ -1511,8 +1512,11 @@ def _make_temp_dir_for_build(TEMPDIR):
15111512
if sysconfig.is_python_build():
15121513
TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build')
15131514
TEMPDIR = os.path.abspath(TEMPDIR)
1514-
if not os.path.exists(TEMPDIR):
1515+
try:
15151516
os.mkdir(TEMPDIR)
1517+
except OSError as e:
1518+
if e.errno != errno.EEXIST:
1519+
raise
15161520

15171521
# Define a writable temp dir that will be used as cwd while running
15181522
# the tests. The name of the dir includes the pid to allow parallel

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ Extensions
269269
Tests
270270
-----
271271

272+
- Fix possible "file already exists" error when running the tests in parallel.
273+
272274
- Issue #11719: Fix message about unexpected test_msilib skip on non-Windows
273275
platforms. Patch by Nadeem Vawda.
274276

0 commit comments

Comments
 (0)