Revision 44c9b4fe
b/lib/utils/__init__.py | ||
---|---|---|
689 | 689 |
return rr |
690 | 690 |
|
691 | 691 |
|
692 |
def ResetTempfileModule(): |
|
693 |
"""Resets the random name generator of the tempfile module. |
|
694 |
|
|
695 |
This function should be called after C{os.fork} in the child process to |
|
696 |
ensure it creates a newly seeded random generator. Otherwise it would |
|
697 |
generate the same random parts as the parent process. If several processes |
|
698 |
race for the creation of a temporary file, this could lead to one not getting |
|
699 |
a temporary name. |
|
700 |
|
|
701 |
""" |
|
702 |
# pylint: disable-msg=W0212 |
|
703 |
if hasattr(tempfile, "_once_lock") and hasattr(tempfile, "_name_sequence"): |
|
704 |
tempfile._once_lock.acquire() |
|
705 |
try: |
|
706 |
# Reset random name generator |
|
707 |
tempfile._name_sequence = None |
|
708 |
finally: |
|
709 |
tempfile._once_lock.release() |
|
710 |
else: |
|
711 |
logging.critical("The tempfile module misses at least one of the" |
|
712 |
" '_once_lock' and '_name_sequence' attributes") |
|
713 |
|
|
714 |
|
|
715 | 692 |
def ForceDictType(target, key_types, allowed_values=None): |
716 | 693 |
"""Force the values of a dict to have certain types. |
717 | 694 |
|
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