STINNER Victor <vstin...@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@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue38162>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to