Skip to content

Commit 0d0b009

Browse files
Use less attempts in _get_default_tempdir().
1 parent 47f7a43 commit 0d0b009

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Lib/tempfile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
if hasattr(_os, 'O_BINARY'):
5858
_bin_openflags |= _os.O_BINARY
5959

60+
# This is more than enough.
61+
# Each name contains more than 40 random bits. Even with a million of
62+
# temporary files, a chance of conflict is less than 1 per million,
63+
# and with 20 attempts it is less than 1e-120.
64+
# Each name contains over 40 random bits. Even with a million temporary
65+
# files, the chance of a conflict is less than 1 in a million, and with
66+
# 20 attempts, it is less than 1e-120.
6067
TMP_MAX = 20
6168

6269
# This variable _was_ unused for legacy reasons, see issue 10354.
@@ -193,8 +200,7 @@ def _get_default_tempdir(dirlist=None):
193200
for dir in dirlist:
194201
if dir != _os.curdir:
195202
dir = _os.path.abspath(dir)
196-
# Try only a few names per directory.
197-
for seq in range(100):
203+
for seq in range(TMP_MAX):
198204
name = next(namer)
199205
filename = _os.path.join(dir, name)
200206
try:

0 commit comments

Comments
 (0)