- # pylint: disable-msg=W0212
- if hasattr(tempfile, "_once_lock") and hasattr(tempfile, "_name_sequence"):
- tempfile._once_lock.acquire()
+ # 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()