summaryrefslogtreecommitdiff
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-25 21:28:15 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-25 21:28:15 +0100
commita5d5bb997b1cb8b5d8a33d67c505ceba3bc3d9e9 (patch)
tree9e88e41369c4d6ebb7dedf6781de00d90d79651f /Lib/tempfile.py
parentda75dd2a9bc56d8a68e106fa10f8dd0052fff869 (diff)
downloadcpython-git-a5d5bb997b1cb8b5d8a33d67c505ceba3bc3d9e9.tar.gz
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, 8 insertions, 1 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 1c718145d3..2023280d03 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -118,9 +118,16 @@ class _RandomNameSequence:
def __init__(self):
self.mutex = _allocate_lock()
- self.rng = _Random()
self.normcase = _os.path.normcase
+ @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