diff options
author | Guido van Rossum <guido@python.org> | 1998-10-14 20:27:05 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-10-14 20:27:05 (GMT) |
commit | b0e5718643f807af590e16ebb8d3eb401a327ca3 (patch) | |
tree | 4bed6dfa67500c544e1f4cc617c0ad0eede5836d /Lib/tempfile.py | |
parent | d3a6a143309a07a398c4e5e7db853e21f78f9a88 (diff) | |
download | cpython-b0e5718643f807af590e16ebb8d3eb401a327ca3.zip cpython-b0e5718643f807af590e16ebb8d3eb401a327ca3.tar.gz cpython-b0e5718643f807af590e16ebb8d3eb401a327ca3.tar.bz2 |
Fix so that after a fork() -- on Unix only -- the template gets
recalculated.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r-- | Lib/tempfile.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 2c9ec9b..6a2730a 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -60,11 +60,17 @@ def gettempdir(): # Function to calculate a prefix of the filename to use +_pid = None + def gettempprefix(): - global template - if template == None: + global template, _pid + if os.name == 'posix' and _pid and _pid != os.getpid(): + # Our pid changed; we must have forked -- zap the template + template = None + if template is None: if os.name == 'posix': - template = '@' + `os.getpid()` + '.' + _pid = os.getpid() + template = '@' + `_pid` + '.' elif os.name == 'nt': template = '~' + `os.getpid()` + '-' elif os.name == 'mac': |