def _run_task_as_child(self, *args, **kwargs): """Runs the task in a subprocess. The subprocess runs _task_wrapper, which handles all task logic. Because the start and end time must be known to the worker, _record_start() and _record_end() are run in the context of the parent process. """ pool = Task._get_task_process_pool() self._record_start() timed_out = False try: process = pool.apply_async(_task_wrapper, args=(self, args, kwargs)) exc = process.get(self.time_limit) if exc is not None: exc.reraise() except multiprocessing.TimeoutError: # Task took too long: hard-terminate the subprocess. timed_out = True # Raise as an exception class that's expected in worker._handle_failures. raise exceptions.TimeoutException(os.strerror(errno.ETIME)) finally: self._record_end() # Check if it timed out. Otherwise, check the worker's memory usage. if timed_out or not pool.apply_async(_is_memory_ok).get(): Task._terminate_task_process_pool()
def run_task(self, *args, **kwargs): raise exceptions.TimeoutException('Task failed.')
def _handle_timeout(signum, frame): raise exceptions.TimeoutException(os.strerror(errno.ETIME))
def _handle_timeout(signum, frame): """Handle timout signal.""" raise exceptions.TimeoutException(error_message)