Revision 44c9b4fe lib/utils/wrapper.py
b/lib/utils/wrapper.py | ||
---|---|---|
29 | 29 |
import fcntl |
30 | 30 |
import os |
31 | 31 |
import select |
32 |
import logging |
|
32 | 33 |
|
33 | 34 |
|
34 | 35 |
def TestDelay(duration): |
... | ... | |
168 | 169 |
(fd, path) = tempfile.mkstemp(*args, **kwargs) |
169 | 170 |
CloseFdNoError(fd) |
170 | 171 |
return path |
172 |
|
|
173 |
|
|
174 |
def ResetTempfileModule(): |
|
175 |
"""Resets the random name generator of the tempfile module. |
|
176 |
|
|
177 |
This function should be called after C{os.fork} in the child process to |
|
178 |
ensure it creates a newly seeded random generator. Otherwise it would |
|
179 |
generate the same random parts as the parent process. If several processes |
|
180 |
race for the creation of a temporary file, this could lead to one not getting |
|
181 |
a temporary name. |
|
182 |
|
|
183 |
""" |
|
184 |
# pylint: disable-msg=W0212 |
|
185 |
if hasattr(tempfile, "_once_lock") and hasattr(tempfile, "_name_sequence"): |
|
186 |
tempfile._once_lock.acquire() |
|
187 |
try: |
|
188 |
# Reset random name generator |
|
189 |
tempfile._name_sequence = None |
|
190 |
finally: |
|
191 |
tempfile._once_lock.release() |
|
192 |
else: |
|
193 |
logging.critical("The tempfile module misses at least one of the" |
|
194 |
" '_once_lock' and '_name_sequence' attributes") |
Also available in: Unified diff