<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"> 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"> 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"> 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"> 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"> 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"> 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"> 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"> 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>None</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>:</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:5.1.2 (sun-harmonics) kombu:5.1.0 py:3.8.7
            billiard:3.6.4.0 py-amqp:5.0.6
platform -&gt; system:Darwin arch:64bit
            kernel version:19.6.0 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:amqp results:rpc:///

deprecated_settings: None
broker_url: 'amqp://****:********@localhost:5672//'
result_backend: 'rpc:///'"><pre class="notranslate"><code class="notranslate">software -&gt; celery:5.1.2 (sun-harmonics) kombu:5.1.0 py:3.8.7
            billiard:3.6.4.0 py-amqp:5.0.6
platform -&gt; system:Darwin arch:64bit
            kernel version:19.6.0 imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:amqp results:rpc:///

deprecated_settings: None
broker_url: 'amqp://****:********@localhost:5672//'
result_backend: 'rpc:///'
</code></pre></div>
<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>: 5.1.0</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="amqp==5.0.6
billiard==3.6.4.0
celery==5.1.2
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.2.0
kombu==5.1.0
prompt-toolkit==3.0.19
pytz==2021.1
six==1.16.0
vine==5.0.0
wcwidth==0.2.5"><pre class="notranslate"><code class="notranslate">amqp==5.0.6
billiard==3.6.4.0
celery==5.1.2
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.2.0
kombu==5.1.0
prompt-toolkit==3.0.19
pytz==2021.1
six==1.16.0
vine==5.0.0
wcwidth==0.2.5
</code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
N/A
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<p dir="auto">We are chaining tasks together and then adding an errback to the chain.<br>
The expectation is that if a task in the chain fails, then the errback will be called,<br>
and the rest of the chain skipped. Our broker is <code class="notranslate">amqp</code> (RabbitMQ), and we are using the <code class="notranslate">rpc</code> backend.</p>
<p dir="auto">This feature worked for 4.4.x and works in 5.0.5. Starting in 5.1.0, the Celery<br>
worker will throw an internal exception and the errback is not called. Below is a simple test case:</p>
<details>
<p dir="auto">
</p><p dir="auto"><em>tasks.py</em></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from celery import Celery
from celery.utils.log import get_task_logger

app = Celery()
app.conf.broker_url = &quot;amqp://****:****@localhost:5672/&quot;
app.conf.result_backend = &quot;rpc://&quot;

logger = get_task_logger(__name__)


@app.task
def task1():
    logger.info(&quot;TASK1&quot;)
    raise ValueError('foo')


@app.task
def task2():
    logger.info(&quot;TASK2&quot;)
    

@app.task
def error_handler(request, exc, traceback):
    logger.error(&quot;ERROR HANDLER&quot;)
    logger.error('Task {0} raised exception: {1!r}'.format(
          request.id, exc))
"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>
<span class="pl-k">from</span> <span class="pl-s1">celery</span>.<span class="pl-s1">utils</span>.<span class="pl-s1">log</span> <span class="pl-k">import</span> <span class="pl-s1">get_task_logger</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>()
<span class="pl-s1">app</span>.<span class="pl-s1">conf</span>.<span class="pl-s1">broker_url</span> <span class="pl-c1">=</span> <span class="pl-s">"amqp://****:****@localhost:5672/"</span>
<span class="pl-s1">app</span>.<span class="pl-s1">conf</span>.<span class="pl-s1">result_backend</span> <span class="pl-c1">=</span> <span class="pl-s">"rpc://"</span>

<span class="pl-s1">logger</span> <span class="pl-c1">=</span> <span class="pl-en">get_task_logger</span>(<span class="pl-s1">__name__</span>)


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-s1">task</span></span>
<span class="pl-k">def</span> <span class="pl-en">task1</span>():
    <span class="pl-s1">logger</span>.<span class="pl-en">info</span>(<span class="pl-s">"TASK1"</span>)
    <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s">'foo'</span>)


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-s1">task</span></span>
<span class="pl-k">def</span> <span class="pl-en">task2</span>():
    <span class="pl-s1">logger</span>.<span class="pl-en">info</span>(<span class="pl-s">"TASK2"</span>)
    

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-s1">task</span></span>
<span class="pl-k">def</span> <span class="pl-en">error_handler</span>(<span class="pl-s1">request</span>, <span class="pl-s1">exc</span>, <span class="pl-s1">traceback</span>):
    <span class="pl-s1">logger</span>.<span class="pl-en">error</span>(<span class="pl-s">"ERROR HANDLER"</span>)
    <span class="pl-s1">logger</span>.<span class="pl-en">error</span>(<span class="pl-s">'Task {0} raised exception: {1!r}'</span>.<span class="pl-en">format</span>(
          <span class="pl-s1">request</span>.<span class="pl-s1">id</span>, <span class="pl-s1">exc</span>))</pre></div>
<p dir="auto">Then run <code class="notranslate">task1</code> and <code class="notranslate">task2</code> in a chain using <code class="notranslate">error_handler</code> as the errback:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from tasks import error_handler, task1, task2

chain = (task1.s() | task2.s())
x = chain.apply_async(link_error=error_handler.s())"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">tasks</span> <span class="pl-k">import</span> <span class="pl-s1">error_handler</span>, <span class="pl-s1">task1</span>, <span class="pl-s1">task2</span>

<span class="pl-s1">chain</span> <span class="pl-c1">=</span> (<span class="pl-s1">task1</span>.<span class="pl-en">s</span>() <span class="pl-c1">|</span> <span class="pl-s1">task2</span>.<span class="pl-en">s</span>())
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">chain</span>.<span class="pl-en">apply_async</span>(<span class="pl-s1">link_error</span><span class="pl-c1">=</span><span class="pl-s1">error_handler</span>.<span class="pl-en">s</span>())</pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto"><code class="notranslate">task1</code> will fail and <code class="notranslate">error_handler</code> should be called:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[INFO/MainProcess] Task tasks.task1[35e2f20e-fc5b-4889-8ae0-9c1a593a15ec] received
[INFO/ForkPoolWorker-7] tasks.task1[35e2f20e-fc5b-4889-8ae0-9c1a593a15ec]: TASK1
[ERROR/ForkPoolWorker-7] tasks.error_handler[None]: ERROR HANDLER
[ERROR/ForkPoolWorker-7] tasks.error_handler[None]: Task 35e2f20e-fc5b-4889-8ae0-9c1a593a15ec raised exception: ValueError('foo')
[ERROR/ForkPoolWorker-7] Task tasks.task1[35e2f20e-fc5b-4889-8ae0-9c1a593a15ec] raised unexpected: ValueError('foo')"><pre class="notranslate"><code class="notranslate">[INFO/MainProcess] Task tasks.task1[35e2f20e-fc5b-4889-8ae0-9c1a593a15ec] received
[INFO/ForkPoolWorker-7] tasks.task1[35e2f20e-fc5b-4889-8ae0-9c1a593a15ec]: TASK1
[ERROR/ForkPoolWorker-7] tasks.error_handler[None]: ERROR HANDLER
[ERROR/ForkPoolWorker-7] tasks.error_handler[None]: Task 35e2f20e-fc5b-4889-8ae0-9c1a593a15ec raised exception: ValueError('foo')
[ERROR/ForkPoolWorker-7] Task tasks.task1[35e2f20e-fc5b-4889-8ae0-9c1a593a15ec] raised unexpected: ValueError('foo')
</code></pre></div>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">The Celery worker logs the following stack trace and <code class="notranslate">error_handler</code> is never called:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ERROR/MainProcess] Pool callback raised exception: AttributeError(&quot;'dict' object has no attribute 'reply_to'&quot;)
Traceback (most recent call last):
  File &quot;/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/billiard/pool.py&quot;, line 1796, in safe_apply_callback
    fun(*args, **kwargs)
  File &quot;/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/celery/worker/request.py&quot;, line 571, in on_failure
    self.task.backend.mark_as_failure(
  File &quot;/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/celery/backends/base.py&quot;, line 199, in mark_as_failure
    self.store_result(
  File &quot;/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/celery/backends/rpc.py&quot;, line 198, in store_result
    routing_key, correlation_id = self.destination_for(task_id, request)
  File &quot;/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/celery/backends/rpc.py&quot;, line 179, in destination_for
    return request.reply_to, request.correlation_id or task_id
AttributeError: 'dict' object has no attribute 'reply_to'"><pre class="notranslate"><code class="notranslate">[ERROR/MainProcess] Pool callback raised exception: AttributeError("'dict' object has no attribute 'reply_to'")
Traceback (most recent call last):
  File "/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/billiard/pool.py", line 1796, in safe_apply_callback
    fun(*args, **kwargs)
  File "/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/celery/worker/request.py", line 571, in on_failure
    self.task.backend.mark_as_failure(
  File "/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/celery/backends/base.py", line 199, in mark_as_failure
    self.store_result(
  File "/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/celery/backends/rpc.py", line 198, in store_result
    routing_key, correlation_id = self.destination_for(task_id, request)
  File "/****/share/virtualenvs/celery5-reply-to-reL48Jin/lib/python3.8/site-packages/celery/backends/rpc.py", line 179, in destination_for
    return request.reply_to, request.correlation_id or task_id
AttributeError: 'dict' object has no attribute 'reply_to'
</code></pre></div>
<p dir="auto">PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="428030532" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/5423" data-hovercard-type="pull_request" data-hovercard-url="/celery/celery/pull/5423/hovercard" href="https://github.com/celery/celery/pull/5423">#5423</a> (to address issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="93878725" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/2700" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/2700/hovercard" href="https://github.com/celery/celery/issues/2700">#2700</a>) made a change which installs a <code class="notranslate">SIGTERM</code> handler within <code class="notranslate">Task.__call__()</code>, which effectively ignores <code class="notranslate">SIGTERM</code>. This is...er...wrong, and leads to the following problems:</p>
<ul dir="auto">
<li>Tasks cannot be called inline within a thread (eg common configurations of <code class="notranslate">uwsgi</code>, or even Django's <code class="notranslate">runserver</code>)</li>
<li>The warm/cold shutdown distinction is erased</li>
<li>The <code class="notranslate">REMAP_SIGTERM</code> configuration value is ignored (used in eg Heroku deployments)</li>
<li>Signal handling by non-worker calling processes is forcibly overridden</li>
<li>Conflicts with Celery's own worker signal handling (see <a href="https://github.com/celery/celery/blob/master/celery/apps/worker.py">worker.py</a> and <a href="https://github.com/celery/celery/blob/master/celery/platforms.py">platforms.py</a>)</li>
</ul>
<p dir="auto">The PR in question was reverted in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="454089143" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/5577" data-hovercard-type="pull_request" data-hovercard-url="/celery/celery/pull/5577/hovercard" href="https://github.com/celery/celery/pull/5577">#5577</a>, then un-reverted in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="455551137" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/5586" data-hovercard-type="pull_request" data-hovercard-url="/celery/celery/pull/5586/hovercard" href="https://github.com/celery/celery/pull/5586">#5586</a>.</p>
<p dir="auto">We've had to add a custom task class and override <code class="notranslate">__call__()</code> for production use to avoid this issue. Please re-revert <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="428030532" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/5423" data-hovercard-type="pull_request" data-hovercard-url="/celery/celery/pull/5423/hovercard" href="https://github.com/celery/celery/pull/5423">#5423</a>; if <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="93878725" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/2700" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/2700/hovercard" href="https://github.com/celery/celery/issues/2700">#2700</a> is still an issue inherent to Celery (as opposed to simply warm/cold shutdown differences), then a different fix should be considered.</p>
<p dir="auto">Edit: after some deeper looks at the code, it seems as though this only applies for inline tasks under the base <code class="notranslate">Task</code> class, as <code class="notranslate">__call__()</code> is optimized away (see <a href="https://github.com/celery/celery/blob/master/celery/app/trace.py#L292">trace.py</a>) for async/dispatched tasks if it hasn't been overridden. AFAICT it <em>would</em> still be a problem if using a custom task class which overrides <code class="notranslate">__call__()</code> and calls <code class="notranslate">super()</code>, however.</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 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"> 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"> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="93878725" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/2700" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/2700/hovercard" href="https://github.com/celery/celery/issues/2700">#2700</a></li>
<li>PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="428030532" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/5423" data-hovercard-type="pull_request" data-hovercard-url="/celery/celery/pull/5423/hovercard" href="https://github.com/celery/celery/pull/5423">#5423</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>:</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:4.4.0rc3 (cliffs) kombu:4.6.4 py:3.7.4
            billiard:3.6.1.0 redis:3.3.7
platform -&gt; system:Linux arch:64bit
            kernel version:4.9.184-linuxkit imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis://mps-redis:6379/0"><pre class="notranslate"><code class="notranslate">software -&gt; celery:4.4.0rc3 (cliffs) kombu:4.6.4 py:3.7.4
            billiard:3.6.1.0 redis:3.3.7
platform -&gt; system:Linux arch:64bit
            kernel version:4.9.184-linuxkit imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:redis results:redis://mps-redis:6379/0
</code></pre></div>
<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>: 4.4.0rc2</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>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<p dir="auto">See <a href="https://github.com/celery/celery/blob/master/celery/app/task.py#L396">https://github.com/celery/celery/blob/master/celery/app/task.py#L396</a></p>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">Should be able to call a task inline in a thread.</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">When calling task inline under Django <code class="notranslate">runserver</code> (which uses threads):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;/app/pipelines/serializers.py&quot;, line 184, in create
    remote_worker=validated_data['with_remote'],
  File &quot;/usr/local/lib/python3.7/site-packages/celery/local.py&quot;, line 191, in __call__
    return self._get_current_object()(*a, **kw)
  File &quot;/usr/local/lib/python3.7/site-packages/celery/app/task.py&quot;, line 396, in __call__
    signal.signal(signal.SIGTERM, handle_sigterm)
  File &quot;/usr/local/lib/python3.7/signal.py&quot;, line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "/app/pipelines/serializers.py", line 184, in create
    remote_worker=validated_data['with_remote'],
  File "/usr/local/lib/python3.7/site-packages/celery/local.py", line 191, in __call__
    return self._get_current_object()(*a, **kw)
  File "/usr/local/lib/python3.7/site-packages/celery/app/task.py", line 396, in __call__
    signal.signal(signal.SIGTERM, handle_sigterm)
  File "/usr/local/lib/python3.7/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
</code></pre></div>