mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +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:
		
						commit
						c24847658f
					
				
					 3 changed files with 43 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue