MCPcopy
hub / github.com/celery/celery / wait_for

Method wait_for

celery/backends/base.py:880–906  ·  view source on GitHub ↗

Wait for task and return its result. If the task raises an exception, this exception will be re-raised by :func:`wait_for`. Raises: celery.exceptions.TimeoutError: If `timeout` is not :const:`None`, and the operation takes longer

(self, task_id,
                 timeout=None, interval=0.5, no_ack=True, on_interval=None)

Source from the content-addressed store, hash-verified

878 return result.maybe_throw(propagate=propagate, callback=callback)
879
880 def wait_for(self, task_id,
881 timeout=None, interval=0.5, no_ack=True, on_interval=None):
882 """Wait for task and return its result.
883
884 If the task raises an exception, this exception
885 will be re-raised by :func:`wait_for`.
886
887 Raises:
888 celery.exceptions.TimeoutError:
889 If `timeout` is not :const:`None`, and the operation
890 takes longer than `timeout` seconds.
891 """
892 self._ensure_not_eager()
893
894 time_elapsed = 0.0
895
896 while 1:
897 meta = self.get_task_meta(task_id)
898 if meta['status'] in states.READY_STATES:
899 return meta
900 if on_interval:
901 on_interval()
902 # avoid hammering the CPU checking status.
903 time.sleep(interval)
904 time_elapsed += interval
905 if timeout and time_elapsed >= timeout:
906 raise TimeoutError('The operation timed out.')
907
908 def add_pending_result(self, result, weak=False):
909 return result

Callers 1

wait_for_pendingMethod · 0.95

Calls 4

TimeoutErrorClass · 0.90
_ensure_not_eagerMethod · 0.45
get_task_metaMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected