def apply_async(self, args=(), kwargs=None, add_to_parent=True, producer=None, **options): app = self.app if app.conf.task_always_eager: return self.apply(args, kwargs, **options) if not self.tasks: return self.freeze() options, group_id, root_id = self._freeze_gid(options) tasks = self._prepared(self.tasks, args, group_id, root_id, app) p = barrier() results = list(self._apply_tasks(tasks, producer, app, p, **options)) result = self.app.GroupResult(group_id, results, ready_barrier=p) p.finalize() # - Special case of group(A.s() | group(B.s(), C.s())) # That is, group with single item that is a chain but the # last task in that chain is a group. # # We cannot actually support arbitrary GroupResults in chains, # but this special case we can. if len(result) == 1 and isinstance(result[0], GroupResult): result = result[0] parent_task = app.current_worker_task if add_to_parent and parent_task: parent_task.add_trail(result) return result
def test_reverse(self): callback = Mock() x = barrier(self.ps, callback=promise(callback)) for p in self.ps: p() self.assertTrue(x.ready) callback.assert_called_with()
def test_cancel(self): x = barrier(self.ps) x.cancel() for p in self.ps: p() x.add(promise()) x.throw(KeyError()) self.assertFalse(x.ready)
def test_evaluate(self): x = barrier(self.ps) x() self.assertFalse(x.ready) x() self.assertFalse(x.ready) x.add(promise()) x() self.assertFalse(x.ready) x() self.assertTrue(x.ready) x() x() with self.assertRaises(ValueError): x.add(promise())
def test_throw(self): x = barrier(self.ps) with self.assertRaises(KeyError): x.throw(KeyError(10))