[issue38162] Import Long Load

STINNER Victor report at bugs.python.org
Mon Sep 16 16:08:02 EDT 2019


STINNER Victor <vstinner at python.org> added the comment:

tempfile uses a low number of random bits per filename, so collision is "likely". Two Python processes might attempt to create the same temporary file "at the same time". Maybe not two processes, but two Python threads.

Rather than writing complex locking mechanism, "for seq in range(TMP_MAX):" retries. While one collision is "likely", TMP_MAX is less likely, especially if TMP_MAX is big.

On my Linux, I get:

pvstinner at apu$ python3
Python 3.7.4 (default, Jul  9 2019, 16:32:37) 
>>> import posix
>>> posix.TMP_MAX
238328

Removing the loop introduces a race condition. You tagged this issue as "performance": well, in Python we don't accept optimizations which make Python "not correct". Correctness matters more than performance.

If tempfile is critical for your application performance, you can easily copy tempfile.py and adapt it for your needs ;-)

--

Well, as Stéphane wrote: you need to eloborate the rationale for your change.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38162>
_______________________________________


More information about the Python-bugs-list mailing list