| OLD | NEW |
| 1 # | 1 # |
| 2 # Module providing various facilities to other parts of the package | 2 # Module providing various facilities to other parts of the package |
| 3 # | 3 # |
| 4 # multiprocessing/util.py | 4 # multiprocessing/util.py |
| 5 # | 5 # |
| 6 # Copyright (c) 2006-2008, R Oudkerk | 6 # Copyright (c) 2006-2008, R Oudkerk |
| 7 # All rights reserved. | 7 # All rights reserved. |
| 8 # | 8 # |
| 9 # Redistribution and use in source and binary forms, with or without | 9 # Redistribution and use in source and binary forms, with or without |
| 10 # modification, are permitted provided that the following conditions | 10 # modification, are permitted provided that the following conditions |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 25 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 26 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 26 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 28 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 29 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 31 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 # SUCH DAMAGE. | 32 # SUCH DAMAGE. |
| 33 # | 33 # |
| 34 | 34 |
| 35 import functools |
| 35 import itertools | 36 import itertools |
| 36 import weakref | 37 import weakref |
| 37 import atexit | 38 import atexit |
| 39 import select |
| 38 import threading # we want threading to install it's | 40 import threading # we want threading to install it's |
| 39 # cleanup function before multiprocessing does | 41 # cleanup function before multiprocessing does |
| 40 | 42 |
| 41 from multiprocessing.process import current_process, active_children | 43 from multiprocessing.process import current_process, active_children |
| 42 | 44 |
| 43 __all__ = [ | 45 __all__ = [ |
| 44 'sub_debug', 'debug', 'info', 'sub_warning', 'get_logger', | 46 'sub_debug', 'debug', 'info', 'sub_warning', 'get_logger', |
| 45 'log_to_stderr', 'get_temp_dir', 'register_after_fork', | 47 'log_to_stderr', 'get_temp_dir', 'register_after_fork', |
| 46 'is_exiting', 'Finalize', 'ForkAwareThreadLock', 'ForkAwareLocal', | 48 'is_exiting', 'Finalize', 'ForkAwareThreadLock', 'ForkAwareLocal', |
| 47 'SUBDEBUG', 'SUBWARNING', | 49 'SUBDEBUG', 'SUBWARNING', |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 self._lock = threading.Lock() | 310 self._lock = threading.Lock() |
| 309 self.acquire = self._lock.acquire | 311 self.acquire = self._lock.acquire |
| 310 self.release = self._lock.release | 312 self.release = self._lock.release |
| 311 register_after_fork(self, ForkAwareThreadLock.__init__) | 313 register_after_fork(self, ForkAwareThreadLock.__init__) |
| 312 | 314 |
| 313 class ForkAwareLocal(threading.local): | 315 class ForkAwareLocal(threading.local): |
| 314 def __init__(self): | 316 def __init__(self): |
| 315 register_after_fork(self, lambda obj : obj.__dict__.clear()) | 317 register_after_fork(self, lambda obj : obj.__dict__.clear()) |
| 316 def __reduce__(self): | 318 def __reduce__(self): |
| 317 return type(self), () | 319 return type(self), () |
| 320 |
| 321 |
| 322 # |
| 323 # Automatic retry after EINTR |
| 324 # |
| 325 |
| 326 def eintr_retry(func, _errors=(EnvironmentError, select.error)): |
| 327 @functools.wraps(func) |
| 328 def wrapped(*args, **kwargs): |
| 329 while True: |
| 330 try: |
| 331 return func(*args, **kwargs) |
| 332 except _errors as e: |
| 333 # select.error has no `errno` attribute |
| 334 if e.args[0] == errno.EINTR: |
| 335 continue |
| 336 raise |
| 337 return wrapped |
| 338 |
| OLD | NEW |