Revision 380bb53a

b/lib/utils/wrapper.py
171 171
  return path
172 172

  
173 173

  
174
def ResetTempfileModule():
174
def ResetTempfileModule(_time=time.time):
175 175
  """Resets the random name generator of the tempfile module.
176 176

  
177 177
  This function should be called after C{os.fork} in the child process to
......
182 182

  
183 183
  """
184 184
  # pylint: disable=W0212
185
  if hasattr(tempfile, "_once_lock") and hasattr(tempfile, "_name_sequence"):
186
    tempfile._once_lock.acquire()
185
  try:
186
    lock = tempfile._once_lock
187
    lock.acquire()
187 188
    try:
188
      # Reset random name generator
189
      tempfile._name_sequence = None
189
      # Re-seed random name generator
190
      if tempfile._name_sequence:
191
        tempfile._name_sequence.rng.seed(hash(_time()) ^ os.getpid())
190 192
    finally:
191
      tempfile._once_lock.release()
192
  else:
193
      lock.release()
194
  except AttributeError:
193 195
    logging.critical("The tempfile module misses at least one of the"
194 196
                     " '_once_lock' and '_name_sequence' attributes")

Also available in: Unified diff