From: Guido van Rossum Date: Wed, 14 Oct 1998 20:27:05 +0000 (+0000) Subject: Fix so that after a fork() -- on Unix only -- the template gets X-Git-Tag: v1.5.2a2~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0e5718643f807af590e16ebb8d3eb401a327ca3;p=python Fix so that after a fork() -- on Unix only -- the template gets recalculated. --- diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 2c9ec9b0d1..6a2730a892 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':