summaryrefslogtreecommitdiffstats
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-01-14 05:05:51 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-01-14 05:05:51 (GMT)
commit2caf8df86802fb24a23ed2cf57674618b5a8f674 (patch)
treed458a669fe9b6733ad2e23eee82b00f39c955b4b /Lib/tempfile.py
parentb9e202b2dc341f6bcca7719eb40d00f5e03ea4cf (diff)
downloadcpython-2caf8df86802fb24a23ed2cf57674618b5a8f674.zip
cpython-2caf8df86802fb24a23ed2cf57674618b5a8f674.tar.gz
cpython-2caf8df86802fb24a23ed2cf57674618b5a8f674.tar.bz2
SF bug 128713: type(mmap_object) blew up on Linux.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r--Lib/tempfile.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 8ac707d..3ad6d7c 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -89,6 +89,7 @@ elif os.name == 'mac':
else:
template = 'tmp' # XXX might choose a better one
+_pidcache = {}
def gettempprefix():
"""Function to calculate a prefix of the filename to use.
@@ -96,9 +97,15 @@ def gettempprefix():
notion, so that concurrent processes don't generate the same prefix.
"""
- global template
if template is None:
- return '@' + `os.getpid()` + '.'
+ p = os.getpid()
+ t = _pidcache.get(p, 0)
+ if t:
+ return t
+ if len(_pidcache) > 100: # stop unbounded growth
+ _pidcache.clear()
+ t = _pidcache[p] = '@' + `p` + '.'
+ return t
else:
return template