Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fail the chain if it's sub task gives an exception
    primarykey
    data
    text
    <p>I have faced a pretty strange issue with celery:</p> <p>There is a chain of tasks, and one of them gives an exception and does several retries</p> <pre><code>chain = (err.si(1) | err.si(2)) result = chain.apply_async() result.state result.get() </code></pre> <p>here is the code of the task:</p> <pre><code>@celery.task(base=MyTask) def err(x): try: if x &lt; 3: raise Exception else: return x+1 except Exception as exp: print "retrying" raise err.retry(args=[x],exc=exp,countdown=5,max_retries=3) </code></pre> <p>The thing is that although the task in chain gives an exception, but the result.state keeps being 'PENDING' and .get() just freezes.</p> <p>I have tried to fail the task in case it reaches maximum retries value:</p> <pre><code>class MyTask(celery.Task): abstract = True def after_return(self, status, retval, task_id, args, kwargs, einfo): if self.max_retries == self.request.retries: self.state = states.FAILURE </code></pre> <p>But although executed separately task is getting marked as FAILED, executing in chain gives same result - PENDING &amp; Freezed get.</p> <p>I expected that the chain will get failed once any of it's tasks will get failed and .get of the result should produce the exception thrown from the task.</p> <p>_<strong><em>UPDATE</em>_</strong> Stack trace given by apply_async with ALWAYS_EAGER=True</p> <pre><code>result = chain.apply_async() Exception Traceback (most recent call last) &lt;ipython-input-4-81202b369b5f&gt; in &lt;module&gt;() ----&gt; 1 result = chain.apply_async() lib/python2.7/site-packages/celery/canvas.pyc in apply_async(self, args, kwargs, **options) 147 # For callbacks: extra args are prepended to the stored args. 148 args, kwargs, options = self._merge(args, kwargs, options) --&gt; 149 return self.type.apply_async(args, kwargs, **options) 150 151 def append_to_list_option(self, key, value): /lib/python2.7/site-packages/celery/app/builtins.pyc in apply_async(self, args, kwargs, group_id, chord, task_id, **options) 232 task_id=None, **options): 233 if self.app.conf.CELERY_ALWAYS_EAGER: --&gt; 234 return self.apply(args, kwargs, **options) 235 options.pop('publisher', None) 236 tasks, results = self.prepare_steps(args, kwargs['tasks']) lib/python2.7/site-packages/celery/app/builtins.pyc in apply(self, args, kwargs, subtask, **options) 249 last, fargs = None, args # fargs passed to first task only 250 for task in kwargs['tasks']: --&gt; 251 res = subtask(task).clone(fargs).apply(last and (last.get(), )) 252 res.parent, last, fargs = last, res, None 253 return last lib/python2.7/site-packages/celery/result.pyc in get(self, timeout, propagate, **kwargs) 677 elif self.state in states.PROPAGATE_STATES: 678 if propagate: --&gt; 679 raise self.result 680 return self.result 681 wait = get Exception: </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload