utils: Move ResetTempfileModule to wrappers module
authorMichael Hanselmann <hansmi@google.com>
Tue, 11 Jan 2011 11:12:46 +0000 (12:12 +0100)
committerMichael Hanselmann <hansmi@google.com>
Tue, 11 Jan 2011 15:32:58 +0000 (16:32 +0100)
It's not exactly a wrapper, but this seemed like the best place.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/utils/__init__.py
lib/utils/wrapper.py

index 171130a..810924e 100644 (file)
@@ -689,29 +689,6 @@ def RunParts(dir_name, env=None, reset_env=False):
   return rr
 
 
-def ResetTempfileModule():
-  """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-msg=W0212
-  if hasattr(tempfile, "_once_lock") and hasattr(tempfile, "_name_sequence"):
-    tempfile._once_lock.acquire()
-    try:
-      # Reset random name generator
-      tempfile._name_sequence = None
-    finally:
-      tempfile._once_lock.release()
-  else:
-    logging.critical("The tempfile module misses at least one of the"
-                     " '_once_lock' and '_name_sequence' attributes")
-
-
 def ForceDictType(target, key_types, allowed_values=None):
   """Force the values of a dict to have certain types.
 
index b87f69c..6cf1654 100644 (file)
@@ -29,6 +29,7 @@ import tempfile
 import fcntl
 import os
 import select
+import logging
 
 
 def TestDelay(duration):
@@ -168,3 +169,26 @@ def GetClosedTempfile(*args, **kwargs):
   (fd, path) = tempfile.mkstemp(*args, **kwargs)
   CloseFdNoError(fd)
   return path
+
+
+def ResetTempfileModule():
+  """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-msg=W0212
+  if hasattr(tempfile, "_once_lock") and hasattr(tempfile, "_name_sequence"):
+    tempfile._once_lock.acquire()
+    try:
+      # Reset random name generator
+      tempfile._name_sequence = None
+    finally:
+      tempfile._once_lock.release()
+  else:
+    logging.critical("The tempfile module misses at least one of the"
+                     " '_once_lock' and '_name_sequence' attributes")