mirror of
https://github.com/python/cpython.git
synced 2025-08-19 08:11:46 +00:00
Issue #12856: Ensure child processes do not inherit the parent's random seed for filename generation in the tempfile module.
Patch by Brian Harring.
This commit is contained in:
parent
da75dd2a9b
commit
a5d5bb997b
3 changed files with 44 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue