summaryrefslogtreecommitdiffstats
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-25 20:28:15 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-25 20:28:15 (GMT)
commit4558bad7d64a7599b46fb56ea2df52319437f3a0 (patch)
tree8cb5015f604888d24cf9cc88f0b3b66609f7ea27 /Lib/tempfile.py
parentfd9ebd4a361805607baea3e038652f207575ced8 (diff)
downloadcpython-4558bad7d64a7599b46fb56ea2df52319437f3a0.zip
cpython-4558bad7d64a7599b46fb56ea2df52319437f3a0.tar.gz
cpython-4558bad7d64a7599b46fb56ea2df52319437f3a0.tar.bz2
Issue #12856: Ensure child processes do not inherit the parent's random seed for filename generation in the tempfile module.
Patch by Brian Harring.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r--Lib/tempfile.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 48b77a8..34dff30 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -112,8 +112,13 @@ class _RandomNameSequence:
characters = "abcdefghijklmnopqrstuvwxyz0123456789_"
- def __init__(self):
- self.rng = _Random()
+ @property
+ def rng(self):
+ cur_pid = _os.getpid()
+ if cur_pid != getattr(self, '_rng_pid', None):
+ self._rng = _Random()
+ self._rng_pid = cur_pid
+ return self._rng
def __iter__(self):
return self