<p dir="auto">Using the method described at <a href="http://docs.celeryproject.org/en/latest/userguide/workers.html#pool-restart-command" rel="nofollow">http://docs.celeryproject.org/en/latest/userguide/workers.html#pool-restart-command</a> only restart 1 process in the worker's process pool but not all. The other processes <em>may</em> restart  only after the worker received other tasks. How can I make sure all the processes of the worker are restarted?</p>
<p dir="auto">For example, using tasks defined in this gist <a href="https://gist.github.com/lebinh/165f7edb95daa08bee54">https://gist.github.com/lebinh/165f7edb95daa08bee54</a> and start a worker with concurrency 2: <code class="notranslate">celery -A tasks worker -l info -c 2</code>. After sending <code class="notranslate">pool_restart</code> command with <code class="notranslate">tasks.app.control.broadcast('pool_restart')</code> I got this log:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[2014-06-05 18:53:43,310: WARNING/Worker-1] worker process shutdown
[2014-06-05 18:53:44,350: WARNING/Worker-3] worker process init
^C
worker: Hitting Ctrl+C again will terminate all running tasks!

worker: Warm shutdown (MainProcess)
[2014-06-05 18:54:05,368: WARNING/Worker-2] worker process shutdown
[2014-06-05 18:54:05,368: WARNING/Worker-3] worker process shutdown"><pre class="notranslate"><code class="notranslate">[2014-06-05 18:53:43,310: WARNING/Worker-1] worker process shutdown
[2014-06-05 18:53:44,350: WARNING/Worker-3] worker process init
^C
worker: Hitting Ctrl+C again will terminate all running tasks!

worker: Warm shutdown (MainProcess)
[2014-06-05 18:54:05,368: WARNING/Worker-2] worker process shutdown
[2014-06-05 18:54:05,368: WARNING/Worker-3] worker process shutdown
</code></pre></div>
<p dir="auto">The worker process 1 is restarted but worker process 2 is still there until I terminate the worker.</p>
<p dir="auto">I'm using the latest version of Celery, 3.1.11 (Cipater), on Ubuntu 14.04 running on EC2.</p>
<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> This has already been asked to the <a href="https://groups.google.com/forum/#!forum/celery-users" rel="nofollow">discussion group</a> first.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the relevant section in the<br>
<a href="http://docs.celeryproject.org/en/latest/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Mandatory Debugging Information</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the contents of <code class="notranslate">pip freeze</code> in the issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Optional Debugging Information</h2>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue on more than one message broker and/or<br>
result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue on more than one operating system.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one workers pool.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue with autoscaling, retries,<br>
ETA/Countdown &amp; rate limits disabled.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have tried reproducing the issue after downgrading<br>
and/or upgrading Celery and its dependencies.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li><a href="https://groups.google.com/g/celery-users/c/3Z07zPfUZQ0/m/VpOCC2PGDQAJ" rel="nofollow">https://groups.google.com/g/celery-users/c/3Z07zPfUZQ0/m/VpOCC2PGDQAJ</a></li>
<li>(semi-related but different) <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="838516728" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/6690" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/6690/hovercard" href="https://github.com/celery/celery/issues/6690">#6690</a></li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>: 5.1.1</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
(celery_movies) C:\Users\markb\PycharmProjects\celery_movies&gt;celery -A celery_movies report
</p><p dir="auto">software -&gt; celery:5.1.1 (sun-harmonics) kombu:5.1.0 py:3.7.2<br>
billiard:3.6.4.0 py-amqp:5.0.6<br>
platform -&gt; system:Windows arch:32bit, WindowsPE<br>
kernel version:10 imp:CPython<br>
loader   -&gt; celery.loaders.app.AppLoader<br>
settings -&gt; transport:amqp results:file:///C:/Users/markb/tmp</p>
<p dir="auto">Exchange: &lt;class 'kombu.entity.Exchange'&gt;<br>
Queue: &lt;class 'kombu.entity.Queue'&gt;<br>
imports: ['celery_movies.tasks']<br>
task_acks_late: True<br>
task_default_exchange: 'my_exchange'<br>
task_queues: [&lt;unbound Queue movies -&gt; &lt;unbound Exchange my_exchange(direct)&gt; -&gt; movies&gt;]<br>
task_routes: {<br>
'movies.<em>': {'queue': 'movies'}, 'news.</em>': {'queue': 'news'}}<br>
deprecated_settings: None<br>
broker_url: 'amqp://guest:********<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/localhost/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/localhost">@localhost</a>:5672//'<br>
result_backend: 'file:///C:/Users/markb/tmp'</p>
<p dir="auto">(celery_news) C:\Users\markb\PycharmProjects\celery_news&gt;celery -A celery_news report</p>
<p dir="auto">software -&gt; celery:5.1.1 (sun-harmonics) kombu:5.1.0 py:3.7.2<br>
billiard:3.6.4.0 py-amqp:5.0.6<br>
platform -&gt; system:Windows arch:32bit, WindowsPE<br>
kernel version:10 imp:CPython<br>
loader   -&gt; celery.loaders.app.AppLoader<br>
settings -&gt; transport:amqp results:file:///C:/Users/markb/tmp</p>
<p dir="auto">Exchange: &lt;class 'kombu.entity.Exchange'&gt;<br>
Queue: &lt;class 'kombu.entity.Queue'&gt;<br>
imports: ['celery_news.tasks']<br>
task_acks_late: True<br>
task_default_exchange: 'my_exchange'<br>
task_queues: [&lt;unbound Queue news -&gt; &lt;unbound Exchange my_exchange(direct)&gt; -&gt; news&gt;,<br>
&lt;unbound Queue celery -&gt; &lt;unbound Exchange my_exchange(direct)&gt; -&gt; celery&gt;]<br>
task_routes: {<br>
'movies.<em>': {'queue': 'movies'}, 'news.</em>': {'queue': 'news'}}<br>
deprecated_settings: None<br>
broker_url: 'amqp://guest:********<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/localhost/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/localhost">@localhost</a>:5672//'<br>
result_backend: 'file:///C:/Users/markb/tmp'</p>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<h2 dir="auto">Required Dependencies</h2>

<ul dir="auto">
<li><strong>Minimal Python Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Celery Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Kombu Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: N/A or Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Client Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: N/A or Unknown</li>
</ul>
<h3 dir="auto">Python Packages</h3>

<details>
<summary><b><code class="notranslate">pip freeze</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
amqp==5.0.6
billiard==3.6.4.0
cached-property==1.5.2
celery==5.1.1
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.2.0
importlib-metadata==4.6.1
kombu==5.1.0
prompt-toolkit==3.0.19
pytz==2021.1
six==1.16.0
typing-extensions==3.10.0.0
vine==5.0.0
wcwidth==0.2.5
zipp==3.5.0
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<details>
<p dir="auto">
Worker <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="23610" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/1" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/1/hovercard" href="https://github.com/celery/celery/issues/1">#1</a>
celery.py (launched via: celery -A celery_movies worker -l info --pool=solo)
</p><div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from celery.app import Celery
from celery_movies import celeryconfig

broker_url = 'amqp://'
celery_app = Celery('movies')
celery_app.config_from_object(celeryconfig)
celery_app.conf.update(broker_url=broker_url,
                        result_backend=&quot;file:///C:/Users/markb/tmp&quot;)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">celery</span>.<span class="pl-s1">app</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>
<span class="pl-k">from</span> <span class="pl-s1">celery_movies</span> <span class="pl-k">import</span> <span class="pl-s1">celeryconfig</span>

<span class="pl-s1">broker_url</span> <span class="pl-c1">=</span> <span class="pl-s">'amqp://'</span>
<span class="pl-s1">celery_app</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>(<span class="pl-s">'movies'</span>)
<span class="pl-s1">celery_app</span>.<span class="pl-en">config_from_object</span>(<span class="pl-s1">celeryconfig</span>)
<span class="pl-s1">celery_app</span>.<span class="pl-s1">conf</span>.<span class="pl-en">update</span>(<span class="pl-s1">broker_url</span><span class="pl-c1">=</span><span class="pl-s1">broker_url</span>,
                        <span class="pl-s1">result_backend</span><span class="pl-c1">=</span><span class="pl-s">"file:///C:/Users/markb/tmp"</span>)</pre></div>
<p dir="auto">celeryconfig.py</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from kombu.common import Queue, Exchange

imports = ['celery_movies.tasks']
task_acks_late = True
task_default_exchange = &quot;my_exchange&quot;

task_queues = [Queue('movies', exchange=Exchange(name=task_default_exchange), routing_key='movies')
               ]

task_routes = {
    'movies.*': {'queue': 'movies'},
    'news.*': {'queue': 'news'}
}"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">kombu</span>.<span class="pl-s1">common</span> <span class="pl-k">import</span> <span class="pl-v">Queue</span>, <span class="pl-v">Exchange</span>

<span class="pl-s1">imports</span> <span class="pl-c1">=</span> [<span class="pl-s">'celery_movies.tasks'</span>]
<span class="pl-s1">task_acks_late</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
<span class="pl-s1">task_default_exchange</span> <span class="pl-c1">=</span> <span class="pl-s">"my_exchange"</span>

<span class="pl-s1">task_queues</span> <span class="pl-c1">=</span> [<span class="pl-v">Queue</span>(<span class="pl-s">'movies'</span>, <span class="pl-s1">exchange</span><span class="pl-c1">=</span><span class="pl-v">Exchange</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s1">task_default_exchange</span>), <span class="pl-s1">routing_key</span><span class="pl-c1">=</span><span class="pl-s">'movies'</span>)
               ]

<span class="pl-s1">task_routes</span> <span class="pl-c1">=</span> {
    <span class="pl-s">'movies.*'</span>: {<span class="pl-s">'queue'</span>: <span class="pl-s">'movies'</span>},
    <span class="pl-s">'news.*'</span>: {<span class="pl-s">'queue'</span>: <span class="pl-s">'news'</span>}
}</pre></div>
<p dir="auto">tasks.py</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from celery_movies.celery import celery_app

@celery_app.task(name='movies.task.publish_movie', bind=True)
def publish_movie(self, *args, **kwargs):
    print(&quot;publishing movie&quot;)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">celery_movies</span>.<span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-s1">celery_app</span>

<span class="pl-en">@<span class="pl-s1">celery_app</span>.<span class="pl-en">task</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'movies.task.publish_movie'</span>, <span class="pl-s1">bind</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">publish_movie</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
    <span class="pl-en">print</span>(<span class="pl-s">"publishing movie"</span>)</pre></div>
<p dir="auto">Worker <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="23611" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/2" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/2/hovercard" href="https://github.com/celery/celery/issues/2">#2</a><br>
celery.py (launched via: celery -A celery_news worker -l info --pool=solo)</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from celery.app import Celery
from celery_news import celeryconfig

broker_url = 'amqp://'
celery_app = Celery('news')
celery_app.config_from_object(celeryconfig)
celery_app.conf.update(broker_url=broker_url,
                       result_backend=&quot;file:///C:/Users/markb/tmp&quot;)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">celery</span>.<span class="pl-s1">app</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>
<span class="pl-k">from</span> <span class="pl-s1">celery_news</span> <span class="pl-k">import</span> <span class="pl-s1">celeryconfig</span>

<span class="pl-s1">broker_url</span> <span class="pl-c1">=</span> <span class="pl-s">'amqp://'</span>
<span class="pl-s1">celery_app</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>(<span class="pl-s">'news'</span>)
<span class="pl-s1">celery_app</span>.<span class="pl-en">config_from_object</span>(<span class="pl-s1">celeryconfig</span>)
<span class="pl-s1">celery_app</span>.<span class="pl-s1">conf</span>.<span class="pl-en">update</span>(<span class="pl-s1">broker_url</span><span class="pl-c1">=</span><span class="pl-s1">broker_url</span>,
                       <span class="pl-s1">result_backend</span><span class="pl-c1">=</span><span class="pl-s">"file:///C:/Users/markb/tmp"</span>)</pre></div>
<p dir="auto">celeryconfig.py</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from kombu.common import Queue, Exchange

imports = ['celery_news.tasks']
task_acks_late = True
task_default_exchange = &quot;my_exchange&quot;

task_queues = [Queue('news', exchange=Exchange(name=task_default_exchange), routing_key='news'),
               Queue('celery', exchange=Exchange(name=task_default_exchange), routing_key='celery')]

task_routes = {
    'movies.*': {'queue': 'movies'},
    'news.*': {'queue': 'news'}
}"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">kombu</span>.<span class="pl-s1">common</span> <span class="pl-k">import</span> <span class="pl-v">Queue</span>, <span class="pl-v">Exchange</span>

<span class="pl-s1">imports</span> <span class="pl-c1">=</span> [<span class="pl-s">'celery_news.tasks'</span>]
<span class="pl-s1">task_acks_late</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
<span class="pl-s1">task_default_exchange</span> <span class="pl-c1">=</span> <span class="pl-s">"my_exchange"</span>

<span class="pl-s1">task_queues</span> <span class="pl-c1">=</span> [<span class="pl-v">Queue</span>(<span class="pl-s">'news'</span>, <span class="pl-s1">exchange</span><span class="pl-c1">=</span><span class="pl-v">Exchange</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s1">task_default_exchange</span>), <span class="pl-s1">routing_key</span><span class="pl-c1">=</span><span class="pl-s">'news'</span>),
               <span class="pl-v">Queue</span>(<span class="pl-s">'celery'</span>, <span class="pl-s1">exchange</span><span class="pl-c1">=</span><span class="pl-v">Exchange</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s1">task_default_exchange</span>), <span class="pl-s1">routing_key</span><span class="pl-c1">=</span><span class="pl-s">'celery'</span>)]

<span class="pl-s1">task_routes</span> <span class="pl-c1">=</span> {
    <span class="pl-s">'movies.*'</span>: {<span class="pl-s">'queue'</span>: <span class="pl-s">'movies'</span>},
    <span class="pl-s">'news.*'</span>: {<span class="pl-s">'queue'</span>: <span class="pl-s">'news'</span>}
}</pre></div>
<p dir="auto">tasks.py</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from celery_news.celery import celery_app

@celery_app.task(name='news.task.publish_news', bind=True)
def publish_news(self, *args, **kwargs):
    print(&quot;publishing news&quot;)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">celery_news</span>.<span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-s1">celery_app</span>

<span class="pl-en">@<span class="pl-s1">celery_app</span>.<span class="pl-en">task</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">'news.task.publish_news'</span>, <span class="pl-s1">bind</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">publish_news</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
    <span class="pl-en">print</span>(<span class="pl-s">"publishing news"</span>)</pre></div>
<p dir="auto">trigger_flow.py</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from celery import group, chain
import uuid
from celery.app import Celery
from celery_movies import celeryconfig


broker_url = 'amqp://'
celery_app = Celery('movies')
celery_app.config_from_object(celeryconfig)
celery_app.conf.update(broker_url=broker_url,
                        result_backend=&quot;file:///C:/Users/markb/tmp&quot;)

movie_task = celery_app.signature('movies.task.publish_movie', task_id=str(uuid.uuid4()), immutable=True)
news_task = celery_app.signature('news.task.publish_news', task_id=str(uuid.uuid4()), immutable=True)

my_chord = chain(movie_task,
                 group(movie_task.set(task_id=str(uuid.uuid4())), movie_task.set(task_id=str(uuid.uuid4()))),
                 news_task)
my_chord.apply_async()"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-s1">group</span>, <span class="pl-s1">chain</span>
<span class="pl-k">import</span> <span class="pl-s1">uuid</span>
<span class="pl-k">from</span> <span class="pl-s1">celery</span>.<span class="pl-s1">app</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>
<span class="pl-k">from</span> <span class="pl-s1">celery_movies</span> <span class="pl-k">import</span> <span class="pl-s1">celeryconfig</span>


<span class="pl-s1">broker_url</span> <span class="pl-c1">=</span> <span class="pl-s">'amqp://'</span>
<span class="pl-s1">celery_app</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>(<span class="pl-s">'movies'</span>)
<span class="pl-s1">celery_app</span>.<span class="pl-en">config_from_object</span>(<span class="pl-s1">celeryconfig</span>)
<span class="pl-s1">celery_app</span>.<span class="pl-s1">conf</span>.<span class="pl-en">update</span>(<span class="pl-s1">broker_url</span><span class="pl-c1">=</span><span class="pl-s1">broker_url</span>,
                        <span class="pl-s1">result_backend</span><span class="pl-c1">=</span><span class="pl-s">"file:///C:/Users/markb/tmp"</span>)

<span class="pl-s1">movie_task</span> <span class="pl-c1">=</span> <span class="pl-s1">celery_app</span>.<span class="pl-en">signature</span>(<span class="pl-s">'movies.task.publish_movie'</span>, <span class="pl-s1">task_id</span><span class="pl-c1">=</span><span class="pl-en">str</span>(<span class="pl-s1">uuid</span>.<span class="pl-en">uuid4</span>()), <span class="pl-s1">immutable</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
<span class="pl-s1">news_task</span> <span class="pl-c1">=</span> <span class="pl-s1">celery_app</span>.<span class="pl-en">signature</span>(<span class="pl-s">'news.task.publish_news'</span>, <span class="pl-s1">task_id</span><span class="pl-c1">=</span><span class="pl-en">str</span>(<span class="pl-s1">uuid</span>.<span class="pl-en">uuid4</span>()), <span class="pl-s1">immutable</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-s1">my_chord</span> <span class="pl-c1">=</span> <span class="pl-en">chain</span>(<span class="pl-s1">movie_task</span>,
                 <span class="pl-en">group</span>(<span class="pl-s1">movie_task</span>.<span class="pl-en">set</span>(<span class="pl-s1">task_id</span><span class="pl-c1">=</span><span class="pl-en">str</span>(<span class="pl-s1">uuid</span>.<span class="pl-en">uuid4</span>())), <span class="pl-s1">movie_task</span>.<span class="pl-en">set</span>(<span class="pl-s1">task_id</span><span class="pl-c1">=</span><span class="pl-en">str</span>(<span class="pl-s1">uuid</span>.<span class="pl-en">uuid4</span>()))),
                 <span class="pl-s1">news_task</span>)
<span class="pl-s1">my_chord</span>.<span class="pl-en">apply_async</span>()</pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>
<p dir="auto">I expect my first task to be handled by the Movies worker, then the chord to start executing the two grouped movie tasks via the Movies worker, and then finally the News worker should pick up and execute the news task</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">First task is handled by the Movies worker, but when the Movies worker tries to move on to the Chord (Group + Chain was upgraded to Chord), system chunks on attempting to submit the chord_unlock task.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[2021-07-07 20:01:48,298: WARNING/MainProcess] C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py:659: RuntimeWarning: Exception raised outside body: Task of kind 'news.task.publish_news' never registered, please make sure it's imported.:
Traceback (most recent call last):
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py&quot;, line 70, in __get__
    return obj_dict[name]
KeyError: 'type'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py&quot;, line 515, in trace_task
    priority=task_priority
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py&quot;, line 1416, in apply_async
    return self.run(tasks, body, args, task_id=task_id, **merged_options)
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py&quot;, line 1488, in run
    max_retries=max_retries,
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py&quot;, line 657, in apply_chord
    self.fallback_chord_unlock(header_result, body, **kwargs)
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py&quot;, line 642, in fallback_chord_unlock
    queue = body.options.get('queue', getattr(body.type, 'queue', None))
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\kombu\utils\objects.py&quot;, line 29, in __get__
    return super().__get__(instance, owner)
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py&quot;, line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py&quot;, line 498, in type
    return self._type or self.app.tasks[self['task']]
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\registry.py&quot;, line 18, in __missing__
    raise self.NotRegistered(key)
celery.exceptions.NotRegistered: 'news.task.publish_news'

  exc, exc_info.traceback)))

[2021-07-07 20:01:48,300: ERROR/MainProcess] Task movies.task.publish_movie[f734ecc4-d174-41c3-b0dd-96544b9815a3] raised unexpected: Task of kind 'news.task.publish_news' never registered, please make sure it's imported.
Traceback (most recent call last):
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py&quot;, line 70, in __get__
    return obj_dict[name]
KeyError: 'type'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py&quot;, line 515, in trace_task
    priority=task_priority
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py&quot;, line 1416, in apply_async
    return self.run(tasks, body, args, task_id=task_id, **merged_options)
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py&quot;, line 1488, in run
    max_retries=max_retries,
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py&quot;, line 657, in apply_chord
    self.fallback_chord_unlock(header_result, body, **kwargs)
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py&quot;, line 642, in fallback_chord_unlock
    queue = body.options.get('queue', getattr(body.type, 'queue', None))
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\kombu\utils\objects.py&quot;, line 29, in __get__
    return super().__get__(instance, owner)
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py&quot;, line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py&quot;, line 498, in type
    return self._type or self.app.tasks[self['task']]
  File &quot;C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\registry.py&quot;, line 18, in __missing__
    raise self.NotRegistered(key)
celery.exceptions.NotRegistered: 'news.task.publish_news'"><pre class="notranslate"><code class="notranslate">[2021-07-07 20:01:48,298: WARNING/MainProcess] C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py:659: RuntimeWarning: Exception raised outside body: Task of kind 'news.task.publish_news' never registered, please make sure it's imported.:
Traceback (most recent call last):
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py", line 70, in __get__
    return obj_dict[name]
KeyError: 'type'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py", line 515, in trace_task
    priority=task_priority
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 1416, in apply_async
    return self.run(tasks, body, args, task_id=task_id, **merged_options)
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 1488, in run
    max_retries=max_retries,
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py", line 657, in apply_chord
    self.fallback_chord_unlock(header_result, body, **kwargs)
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py", line 642, in fallback_chord_unlock
    queue = body.options.get('queue', getattr(body.type, 'queue', None))
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\kombu\utils\objects.py", line 29, in __get__
    return super().__get__(instance, owner)
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py", line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 498, in type
    return self._type or self.app.tasks[self['task']]
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\registry.py", line 18, in __missing__
    raise self.NotRegistered(key)
celery.exceptions.NotRegistered: 'news.task.publish_news'

  exc, exc_info.traceback)))

[2021-07-07 20:01:48,300: ERROR/MainProcess] Task movies.task.publish_movie[f734ecc4-d174-41c3-b0dd-96544b9815a3] raised unexpected: Task of kind 'news.task.publish_news' never registered, please make sure it's imported.
Traceback (most recent call last):
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py", line 70, in __get__
    return obj_dict[name]
KeyError: 'type'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\trace.py", line 515, in trace_task
    priority=task_priority
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 1416, in apply_async
    return self.run(tasks, body, args, task_id=task_id, **merged_options)
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 1488, in run
    max_retries=max_retries,
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py", line 657, in apply_chord
    self.fallback_chord_unlock(header_result, body, **kwargs)
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\backends\base.py", line 642, in fallback_chord_unlock
    queue = body.options.get('queue', getattr(body.type, 'queue', None))
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\kombu\utils\objects.py", line 29, in __get__
    return super().__get__(instance, owner)
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\cached_property.py", line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\canvas.py", line 498, in type
    return self._type or self.app.tasks[self['task']]
  File "C:\Users\markb\.virtualenvs\celery_movies\lib\site-packages\celery\app\registry.py", line 18, in __missing__
    raise self.NotRegistered(key)
celery.exceptions.NotRegistered: 'news.task.publish_news'
</code></pre></div>
<p dir="auto">This is because the task signatures have no body.type attribute set so a KeyError ends up being thrown when executing the queue = line (and the priority = line)</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    def fallback_chord_unlock(self, header_result, body, countdown=1,
                              **kwargs):
        kwargs['result'] = [r.as_tuple() for r in header_result]
        queue = body.options.get('queue', getattr(body.type, 'queue', None))
        priority = body.options.get('priority', getattr(body.type, 'priority', 0))
        self.app.tasks['celery.chord_unlock'].apply_async(
            (header_result.id, body,), kwargs,
            countdown=countdown,
            queue=queue,
            priority=priority,
        )"><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">fallback_chord_unlock</span>(<span class="pl-s1">self</span>, <span class="pl-s1">header_result</span>, <span class="pl-s1">body</span>, <span class="pl-s1">countdown</span><span class="pl-c1">=</span><span class="pl-c1">1</span>,
                              <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-s1">kwargs</span>[<span class="pl-s">'result'</span>] <span class="pl-c1">=</span> [<span class="pl-s1">r</span>.<span class="pl-en">as_tuple</span>() <span class="pl-k">for</span> <span class="pl-s1">r</span> <span class="pl-c1">in</span> <span class="pl-s1">header_result</span>]
        <span class="pl-s1">queue</span> <span class="pl-c1">=</span> <span class="pl-s1">body</span>.<span class="pl-s1">options</span>.<span class="pl-en">get</span>(<span class="pl-s">'queue'</span>, <span class="pl-en">getattr</span>(<span class="pl-s1">body</span>.<span class="pl-s1">type</span>, <span class="pl-s">'queue'</span>, <span class="pl-c1">None</span>))
        <span class="pl-s1">priority</span> <span class="pl-c1">=</span> <span class="pl-s1">body</span>.<span class="pl-s1">options</span>.<span class="pl-en">get</span>(<span class="pl-s">'priority'</span>, <span class="pl-en">getattr</span>(<span class="pl-s1">body</span>.<span class="pl-s1">type</span>, <span class="pl-s">'priority'</span>, <span class="pl-c1">0</span>))
        <span class="pl-s1">self</span>.<span class="pl-s1">app</span>.<span class="pl-s1">tasks</span>[<span class="pl-s">'celery.chord_unlock'</span>].<span class="pl-en">apply_async</span>(
            (<span class="pl-s1">header_result</span>.<span class="pl-s1">id</span>, <span class="pl-s1">body</span>,), <span class="pl-s1">kwargs</span>,
            <span class="pl-s1">countdown</span><span class="pl-c1">=</span><span class="pl-s1">countdown</span>,
            <span class="pl-s1">queue</span><span class="pl-c1">=</span><span class="pl-s1">queue</span>,
            <span class="pl-s1">priority</span><span class="pl-c1">=</span><span class="pl-s1">priority</span>,
        )</pre></div>
<p dir="auto">I believe a solution could be the following, but i'm not confident this doesnt impact something else in Celery</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    def fallback_chord_unlock(self, header_result, body, countdown=1,
                              **kwargs):
        kwargs['result'] = [r.as_tuple() for r in header_result]
        body_type = body.get('type', None)
        queue = body.options.get('queue', getattr(body_type, 'queue', None))
        priority = body.options.get('priority', getattr(body_type, 'priority', 0))
        self.app.tasks['celery.chord_unlock'].apply_async(
            (header_result.id, body,), kwargs,
            countdown=countdown,
            queue=queue,
            priority=priority,
        )"><pre class="notranslate">    <span class="pl-k">def</span> <span class="pl-en">fallback_chord_unlock</span>(<span class="pl-s1">self</span>, <span class="pl-s1">header_result</span>, <span class="pl-s1">body</span>, <span class="pl-s1">countdown</span><span class="pl-c1">=</span><span class="pl-c1">1</span>,
                              <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-s1">kwargs</span>[<span class="pl-s">'result'</span>] <span class="pl-c1">=</span> [<span class="pl-s1">r</span>.<span class="pl-en">as_tuple</span>() <span class="pl-k">for</span> <span class="pl-s1">r</span> <span class="pl-c1">in</span> <span class="pl-s1">header_result</span>]
        <span class="pl-s1">body_type</span> <span class="pl-c1">=</span> <span class="pl-s1">body</span>.<span class="pl-en">get</span>(<span class="pl-s">'type'</span>, <span class="pl-c1">None</span>)
        <span class="pl-s1">queue</span> <span class="pl-c1">=</span> <span class="pl-s1">body</span>.<span class="pl-s1">options</span>.<span class="pl-en">get</span>(<span class="pl-s">'queue'</span>, <span class="pl-en">getattr</span>(<span class="pl-s1">body_type</span>, <span class="pl-s">'queue'</span>, <span class="pl-c1">None</span>))
        <span class="pl-s1">priority</span> <span class="pl-c1">=</span> <span class="pl-s1">body</span>.<span class="pl-s1">options</span>.<span class="pl-en">get</span>(<span class="pl-s">'priority'</span>, <span class="pl-en">getattr</span>(<span class="pl-s1">body_type</span>, <span class="pl-s">'priority'</span>, <span class="pl-c1">0</span>))
        <span class="pl-s1">self</span>.<span class="pl-s1">app</span>.<span class="pl-s1">tasks</span>[<span class="pl-s">'celery.chord_unlock'</span>].<span class="pl-en">apply_async</span>(
            (<span class="pl-s1">header_result</span>.<span class="pl-s1">id</span>, <span class="pl-s1">body</span>,), <span class="pl-s1">kwargs</span>,
            <span class="pl-s1">countdown</span><span class="pl-c1">=</span><span class="pl-s1">countdown</span>,
            <span class="pl-s1">queue</span><span class="pl-c1">=</span><span class="pl-s1">queue</span>,
            <span class="pl-s1">priority</span><span class="pl-c1">=</span><span class="pl-s1">priority</span>,
        )</pre></div>