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

  This function should be called after C{os.fork} in the child process to
  ensure it creates a newly seeded random generator. Otherwise it would
  generate the same random parts as the parent process. If several processes
  race for the creation of a temporary file, this could lead to one not getting
  a temporary name.

  """
  # pylint: disable=W0212
  if ((sys.hexversion >= 0x020703F0 and sys.hexversion < 0x03000000) or
      sys.hexversion >= 0x030203F0):
    # Python 2.7 automatically resets the RNG on pid changes (i.e. forking)
    return

  try:
    lock = tempfile._once_lock
    lock.acquire()
    try:
      # Re-seed random name generator
      if tempfile._name_sequence:
        tempfile._name_sequence.rng.seed(hash(_time()) ^ os.getpid())
    finally:
      lock.release()
  except __HOLE__:
    logging.critical("The tempfile module misses at least one of the"
                     " '_once_lock' and '_name_sequence' attributes")
dataset/ETHPy150Open ganeti/ganeti/lib/utils/wrapper.py/ResetTempfileModule