Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0e5718

Browse files
committed
Fix so that after a fork() -- on Unix only -- the template gets
recalculated.
1 parent d3a6a14 commit b0e5718

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Lib/tempfile.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ def gettempdir():
6060

6161
# Function to calculate a prefix of the filename to use
6262

63+
_pid = None
64+
6365
def gettempprefix():
64-
global template
65-
if template == None:
66+
global template, _pid
67+
if os.name == 'posix' and _pid and _pid != os.getpid():
68+
# Our pid changed; we must have forked -- zap the template
69+
template = None
70+
if template is None:
6671
if os.name == 'posix':
67-
template = '@' + `os.getpid()` + '.'
72+
_pid = os.getpid()
73+
template = '@' + `_pid` + '.'
6874
elif os.name == 'nt':
6975
template = '~' + `os.getpid()` + '-'
7076
elif os.name == 'mac':

0 commit comments

Comments
 (0)