MCPcopy
hub / github.com/celery/celery / collect

Method collect

celery/result.py:274–321  ·  view source on GitHub ↗

Collect results as they return. Iterator, like :meth:`get` will wait for the task to complete, but will also follow :class:`AsyncResult` and :class:`ResultSet` returned by the task, yielding ``(result, value)`` tuples for each result in the tree. An example

(self, intermediate=False, **kwargs)

Source from the content-addressed store, hash-verified

272 node = node.parent
273
274 def collect(self, intermediate=False, **kwargs):
275 """Collect results as they return.
276
277 Iterator, like :meth:`get` will wait for the task to complete,
278 but will also follow :class:`AsyncResult` and :class:`ResultSet`
279 returned by the task, yielding ``(result, value)`` tuples for each
280 result in the tree.
281
282 An example would be having the following tasks:
283
284 .. code-block:: python
285
286 from celery import group
287 from proj.celery import app
288
289 @app.task(trail=True)
290 def A(how_many):
291 return group(B.s(i) for i in range(how_many))()
292
293 @app.task(trail=True)
294 def B(i):
295 return pow2.delay(i)
296
297 @app.task(trail=True)
298 def pow2(i):
299 return i ** 2
300
301 .. code-block:: pycon
302
303 >>> from celery.result import ResultBase
304 >>> from proj.tasks import A
305
306 >>> result = A.delay(10)
307 >>> [v for v in result.collect()
308 ... if not isinstance(v, (ResultBase, tuple))]
309 [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
310
311 Note:
312 The ``Task.trail`` option must be enabled
313 so that the list of children is stored in ``result.children``.
314 This is the default but enabled explicitly for illustration.
315
316 Yields:
317 Tuple[AsyncResult, Any]: tuples containing the result instance
318 of the child task, and the return value of that task.
319 """
320 for _, R in self.iterdeps(intermediate=intermediate):
321 yield R, R.get(**kwargs)
322
323 def get_leaf(self):
324 value = None

Calls 2

iterdepsMethod · 0.95
getMethod · 0.45