如上所述,Celery覆蓋了__or__
運營商,具體如下:
def __or__(self, other):
if isinstance(other, group):
other = maybe_unroll_group(other)
if not isinstance(self, chain) and isinstance(other, chain):
return chain((self,) + other.tasks, app=self._app)
elif isinstance(other, chain):
return chain(*self.tasks + other.tasks, app=self._app)
elif isinstance(other, Signature):
if isinstance(self, chain):
return chain(*self.tasks + (other,), app=self._app)
return chain(self, other, app=self._app)
return NotImplemented
全面實施是在這裏:https://github.com/celery/celery/blob/master/celery/canvas.py#L324