如上所述,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