celery.result
celery.result
Task results/state and groups of results.
class celery.result.ResultBase[源代码]
Base class for all results
parent = None
Parent result (if part of a chain)
class celery.result.AsyncResult(id, backend=None, task_name=None, app=None, parent=None)[源代码]
Query task state.
参数: |
---|
exception TimeoutError
Error raised for timeouts.
AsyncResult.app = None
AsyncResult.as_tuple()
AsyncResult.backend = None
The task result backend to use.
AsyncResult.build_graph(intermediate=False, formatter=None)[源代码]
AsyncResult.children None[源代码]
AsyncResult.collect(intermediate=False, \*kwargs*)[源代码]
Iterator, like get() will wait for the task to complete, but will also follow AsyncResult and ResultSet returned by the task, yielding for each result in the tree.
An example would be having the following tasks:
@task()
def A(how_many):
return group(B.s(i) for i in range(how_many))
@task()
def B(i):
return pow2.delay(i)
@task()
def pow2(i):
return i ** 2
Calling collect() would return:
>>> from proj.tasks import A
>>> result = A.delay(10)
>>> list(result.collect())
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
AsyncResult.failed()[源代码]
Returns True if the task failed.
AsyncResult.forget()[源代码]
Forget about (and possibly remove the result of) this task.
AsyncResult.get(timeout=None, propagate=True, interval=0.5)[源代码]
Wait until task is ready, and return its result.
警告
Waiting for tasks within a task may lead to deadlocks. Please read Avoid launching synchronous subtasks.
参数: - timeout – How long to wait, in seconds, before the operation times out.
- propagate – Re-raise exception if the task failed.
- interval – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the amqp result store backend, as it does not use polling.
引发 celery.exceptions.TimeoutError: if timeout is not None and the result does not arrive within timeout seconds.
If the remote call raised an exception then that exception will be re-raised.
AsyncResult.get_leaf()[源代码]
AsyncResult.graph None[源代码]
AsyncResult.id = None
The task’s UUID.
AsyncResult.info None
When the task has been executed, this contains the return value. If the task raised an exception, this will be the exception instance.
AsyncResult.iterdeps(intermediate=False)[源代码]
AsyncResult.ready()[源代码]
Returns True if the task has been executed.
If the task is still running, pending, or is waiting for retry then False is returned.
AsyncResult.result None[源代码]
When the task has been executed, this contains the return value. If the task raised an exception, this will be the exception instance.
AsyncResult.revoke(connection=None, terminate=False, signal=None, wait=False, timeout=None)[源代码]
Send revoke signal to all workers.
Any worker receiving the task, or having reserved the task, must ignore it.
参数: - terminate – Also terminate the process currently working on the task (if any).
- signal – Name of signal to send to process if terminate. Default is TERM.
- wait – Wait for replies from workers. Will wait for 1 second by default or you can specify a custom timeout.
- timeout – Time in seconds to wait for replies if wait enabled.
AsyncResult.serializable()[源代码]
AsyncResult.state None[源代码]
The tasks current state.
Possible values includes:
PENDING
The task is waiting for execution.
STARTED
The task has been started.
RETRY
The task is to be retried, possibly because of failure.
FAILURE
The task raised an exception, or has exceeded the retry limit. The result attribute then contains the exception raised by the task.
SUCCESS
The task executed successfully. The result attribute then contains the tasks return value.
AsyncResult.status None
The tasks current state.
Possible values includes:
PENDING
The task is waiting for execution.
STARTED
The task has been started.
RETRY
The task is to be retried, possibly because of failure.
FAILURE
The task raised an exception, or has exceeded the retry limit. The result attribute then contains the exception raised by the task.
SUCCESS
The task executed successfully. The result attribute then contains the tasks return value.
AsyncResult.successful()[源代码]
Returns True if the task executed successfully.
AsyncResult.supports_native_join None[源代码]
AsyncResult.task_id None
compat alias to id
AsyncResult.traceback None[源代码]
Get the traceback of a failed task.
AsyncResult.wait(timeout=None, propagate=True, interval=0.5)
Wait until task is ready, and return its result.
警告
Waiting for tasks within a task may lead to deadlocks. Please read Avoid launching synchronous subtasks.
参数: - timeout – How long to wait, in seconds, before the operation times out.
- propagate – Re-raise exception if the task failed.
- interval – Time to wait (in seconds) before retrying to retrieve the result. Note that this does not have any effect when using the amqp result store backend, as it does not use polling.
引发 celery.exceptions.TimeoutError: if timeout is not None and the result does not arrive within timeout seconds.
If the remote call raised an exception then that exception will be re-raised.
class celery.result.ResultSet(results, app=None, \*kwargs*)[源代码]
Working with more than one result.
参数: | results – List of result instances. |
---|
add(result)[源代码]
Add AsyncResult as a new member of the set.
Does nothing if the result is already a member.
app = None
clear()[源代码]
Remove all results from this set.
completed_count()[源代码]
Task completion count.
返回: the number of tasks completed. discard(result)[源代码]
Remove result from the set if it is a member.
If it is not a member, do nothing.
failed()[源代码]
Did any of the tasks fail?
返回: True if one of the tasks failed. (i.e., raised an exception) forget()[源代码]
Forget about (and possible remove the result of) all the tasks.
get(timeout=None, propagate=True, interval=0.5, callback=None)[源代码]
See join()
This is here for API compatibility with AsyncResult, in addition it uses join_native() if available for the current result backend.
iter_native(timeout=None, interval=0.5)[源代码]
Backend optimized version of iterate().
2.2 新版功能.
Note that this does not support collecting the results for different task types using different backends.
This is currently only supported by the amqp, Redis and cache result backends.
iterate(timeout=None, propagate=True, interval=0.5)[源代码]
Iterate over the return values of the tasks as they finish one by one.
Raises: The exception if any of the tasks raised an exception. join(timeout=None, propagate=True, interval=0.5, callback=None)[源代码]
Gathers the results of all tasks as a list in order.
注解
This can be an expensive operation for result store backends that must resort to polling (e.g. database).
You should consider using join_native() if your backend supports it.
警告
Waiting for tasks within a task may lead to deadlocks. Please see Avoid launching synchronous subtasks.
参数: - timeout – The number of seconds to wait for results before the operation times out.
- propagate – If any of the tasks raises an exception, the exception will be re-raised.
- interval – Time to wait (in seconds) before retrying to retrieve a result from the set. Note that this does not have any effect when using the amqp result store backend, as it does not use polling.
- callback – Optional callback to be called for every result received. Must have signature (task_id, value) No results will be returned by this function if a callback is specified. The order of results is also arbitrary when a callback is used.
引发 celery.exceptions.TimeoutError: if timeout is not None and the operation takes longer than timeout seconds.
join_native(timeout=None, propagate=True, interval=0.5, callback=None)[源代码]
Backend optimized version of join().
2.2 新版功能.
Note that this does not support collecting the results for different task types using different backends.
This is currently only supported by the amqp, Redis and cache result backends.
ready()[源代码]
Did all of the tasks complete? (either by success of failure).
返回: True if all of the tasks has been executed. remove(result)[源代码]
Remove result from the set; it must be a member.
引发 KeyError: if the result is not a member. results = None
List of results in in the set.
revoke(connection=None, terminate=False, signal=None, wait=False, timeout=None)[源代码]
Send revoke signal to all workers for all tasks in the set.
参数: - terminate – Also terminate the process currently working on the task (if any).
- signal – Name of signal to send to process if terminate. Default is TERM.
- wait – Wait for replies from worker. Will wait for 1 second by default or you can specify a custom timeout.
- timeout – Time in seconds to wait for replies if wait enabled.
subtasks None[源代码]
Deprecated alias to results.
successful()[源代码]
Was all of the tasks successful?
返回: True if all of the tasks finished successfully (i.e. did not raise an exception). supports_native_join None[源代码]
update(results)[源代码]
Update set with the union of itself and an iterable with results.
waiting()[源代码]
Are any of the tasks incomplete?
返回: True if one of the tasks are still waiting for execution.
class celery.result.GroupResult(id=None, results=None, \*kwargs*)[源代码]
Like ResultSet, but with an associated id.
This type is returned by group, and the deprecated TaskSet, meth:~celery.task.TaskSet.apply_async method.
It enables inspection of the tasks state and return values as a single entity.
参数: |
|
---|
as_tuple()
children None[源代码]
delete(backend=None)[源代码]
Remove this result if it was previously saved.
id = None
The UUID of the group.
classmethod restore(id, backend=None)[源代码]
Restore previously saved group result.
results = None
List/iterator of results in the group
save(backend=None)[源代码]
Save group-result for later retrieval using restore().
Example:
>>> def save_and_restore(result):
... result.save()
... result = GroupResult.restore(result.id)
serializable()[源代码]
class celery.result.EagerResult(id, ret_value, state, traceback=None)[源代码]
Result that we know has already been executed.
forget()[源代码]
get(timeout=None, propagate=True, \*kwargs*)[源代码]
ready()[源代码]
result None[源代码]
The tasks return value
revoke(\args, **kwargs*)[源代码]
state None[源代码]
The tasks state.
status None
The tasks state.
supports_native_join None[源代码]
task_name = None
traceback None[源代码]
The traceback if the task failed.
wait(timeout=None, propagate=True, \*kwargs*)
celery.result.result_from_tuple(r, app=None)