summaryrefslogtreecommitdiff
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-25 21:29:27 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-25 21:29:27 +0100
commitc24847658fb1e676391d3db1096219581cd2782c (patch)
tree0077927f8066b0ed872f5f2c4947e9dd13290b02 /Lib/tempfile.py
parentcad939bf9d83cd7d9f0b74076e81c3b1de16d88d (diff)
parent4558bad7d64a7599b46fb56ea2df52319437f3a0 (diff)
downloadcpython-git-c24847658fb1e676391d3db1096219581cd2782c.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, 7 insertions, 2 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index e3afa3b0ac..39ebf5a943 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -108,8 +108,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