<h1 dir="auto">Expected Behavior</h1>
<p dir="auto">Catch <code class="notranslate">billiard.exceptions.Terminated</code> and don't throw any error.</p>
<h1 dir="auto">Actual Behavior</h1>
<p dir="auto">As the title says <code class="notranslate">billiard.exceptions.Terminated</code> exception is not caught even when it is defined in <code class="notranslate">throws</code> argument of celery task decorator.</p>
<h1 dir="auto">Steps to Reproduce</h1>
<h2 dir="auto">Minimally Reproducible Test Case</h2>
<p dir="auto">I created a file <code class="notranslate">celery_test.py</code></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import time

from celery import Celery
from billiard.exceptions import Terminated

app = Celery('celery_test', broker='amqp://guest:guest@localhost//')


@app.task(throws=(Terminated, ))
def task():
    time.sleep(50)


if __name__ == &quot;__main__&quot;:
    task_id = task.delay().id
    app.control.revoke(task_id, terminate=True)
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">time</span>

<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">billiard</span>.<span class="pl-s1">exceptions</span> <span class="pl-k">import</span> <span class="pl-v">Terminated</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>(<span class="pl-s">'celery_test'</span>, <span class="pl-s1">broker</span><span class="pl-c1">=</span><span class="pl-s">'amqp://guest:guest@localhost//'</span>)


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">task</span>(<span class="pl-s1">throws</span><span class="pl-c1">=</span>(<span class="pl-v">Terminated</span>, ))</span>
<span class="pl-k">def</span> <span class="pl-en">task</span>():
    <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">50</span>)


<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">"__main__"</span>:
    <span class="pl-s1">task_id</span> <span class="pl-c1">=</span> <span class="pl-s1">task</span>.<span class="pl-en">delay</span>().<span class="pl-s1">id</span>
    <span class="pl-s1">app</span>.<span class="pl-s1">control</span>.<span class="pl-en">revoke</span>(<span class="pl-s1">task_id</span>, <span class="pl-s1">terminate</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)</pre></div>
<p dir="auto">Then I ran a worker like this:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ celery -A celery_test worker -l INFO -n test_worker"><pre class="notranslate">$ celery -A celery_test worker -l INFO -n test_worker</pre></div>
<p dir="auto">It returned:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[2019-08-29 14:41:14,384: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2019-08-29 14:41:14,395: INFO/MainProcess] mingle: searching for neighbors
[2019-08-29 14:41:15,419: INFO/MainProcess] mingle: all alone
[2019-08-29 14:41:15,439: INFO/MainProcess] celery@test_worker ready.
[2019-08-29 14:41:16,770: INFO/MainProcess] Received task: celery_test.task[e6d6383e-2610-44bb-99fa-ed97f8ff309c]  
[2019-08-29 14:41:16,852: INFO/MainProcess] Terminating e6d6383e-2610-44bb-99fa-ed97f8ff309c (Signals.SIGTERM)
[2019-08-29 14:41:16,865: ERROR/MainProcess] Task handler raised error: Terminated(15,)
Traceback (most recent call last):
  File &quot;/home/jozef/.pyenv/versions/3.6.5/lib/python3.6/site-packages/billiard/pool.py&quot;, line 1769, in _set_terminated
    raise Terminated(-(signum or 0))
billiard.exceptions.Terminated: 15
"><pre class="notranslate"><code class="notranslate">[2019-08-29 14:41:14,384: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2019-08-29 14:41:14,395: INFO/MainProcess] mingle: searching for neighbors
[2019-08-29 14:41:15,419: INFO/MainProcess] mingle: all alone
[2019-08-29 14:41:15,439: INFO/MainProcess] celery@test_worker ready.
[2019-08-29 14:41:16,770: INFO/MainProcess] Received task: celery_test.task[e6d6383e-2610-44bb-99fa-ed97f8ff309c]  
[2019-08-29 14:41:16,852: INFO/MainProcess] Terminating e6d6383e-2610-44bb-99fa-ed97f8ff309c (Signals.SIGTERM)
[2019-08-29 14:41:16,865: ERROR/MainProcess] Task handler raised error: Terminated(15,)
Traceback (most recent call last):
  File "/home/jozef/.pyenv/versions/3.6.5/lib/python3.6/site-packages/billiard/pool.py", line 1769, in _set_terminated
    raise Terminated(-(signum or 0))
billiard.exceptions.Terminated: 15

</code></pre></div>
<h3 dir="auto">Python Packages</h3>
<details>
alembic==1.0.10
<p dir="auto">amqp==2.5.1</p>
<p dir="auto">anyjson==0.3.3</p>
<p dir="auto">arrow==0.12.1</p>
<p dir="auto">asn1crypto==0.24.0</p>
<p dir="auto">Babel==2.5.1</p>
<p dir="auto">bcrypt==3.1.6</p>
<p dir="auto">beautifulsoup4==4.6.0</p>
<p dir="auto">billiard==3.6.1.0</p>
<p dir="auto">cached-property==1.4.0</p>
<p dir="auto">cachetools==2.0.0</p>
<p dir="auto">celery==4.3.0</p>
<p dir="auto">certifi==2018.1.18</p>
<p dir="auto">cffi==1.12.1</p>
<p dir="auto">chardet==3.0.4</p>
<p dir="auto">Click==7.0</p>
<p dir="auto">cryptography==2.5</p>
<p dir="auto">decorator==4.3.2</p>
<p dir="auto">docopt==0.6.2</p>
<p dir="auto">docopt-dispatch==0.0.2</p>
<p dir="auto">elasticsearch==6.3.1</p>
<p dir="auto">emoji==0.4.5</p>
<p dir="auto">eventlet==0.22.1</p>
<p dir="auto">Fabric3==1.14.post1</p>
<p dir="auto">Flask==0.12.4</p>
<p dir="auto">flower==0.8.1</p>
<p dir="auto">graypy==0.2.14</p>
<p dir="auto">greenlet==0.4.15</p>
<p dir="auto">gspread==3.1.0</p>
<p dir="auto">gunicorn==19.7.1</p>
<p dir="auto">httplib2==0.12.1</p>
<p dir="auto">idna==2.7</p>
<p dir="auto">ijson==2.3</p>
<p dir="auto">importlib-metadata==0.19</p>
<p dir="auto">itsdangerous==0.24</p>
<p dir="auto">Jinja2==2.10</p>
<p dir="auto">jsonpath-ng==1.4.3</p>
<p dir="auto">kombu==4.6.4</p>
<p dir="auto">lxml==4.1.1</p>
<p dir="auto">Mako==1.0.7</p>
<p dir="auto">MarkupSafe==1.1.0</p>
<p dir="auto">minio==3.0.3</p>
<p dir="auto">more-itertools==7.2.0</p>
<p dir="auto">oauth2client==4.1.3</p>
<p dir="auto">ordered-set==3.1.1</p>
<p dir="auto">ordereddict==1.1</p>
<p dir="auto">paramiko==2.4.2</p>
<p dir="auto">pika==0.11.2</p>
<p dir="auto">pipenv==2018.11.26</p>
<p dir="auto">ply==3.11</p>
<p dir="auto">prometheus-client==0.3.1</p>
<p dir="auto">psutil==5.4.3</p>
<p dir="auto">psycopg2==2.8.3</p>
<p dir="auto">pyasn1==0.4.5</p>
<p dir="auto">pyasn1-modules==0.2.4</p>
<p dir="auto">pycparser==2.19</p>
<p dir="auto">pycryptodomex==3.6.6</p>
<p dir="auto">PyJWT==1.6.4</p>
<p dir="auto">PyNaCl==1.3.0</p>
<p dir="auto">pyrabbit==1.1.0</p>
<p dir="auto">pysftp==0.2.8</p>
<p dir="auto">python-dateutil==2.8.0</p>
<p dir="auto">python-editor==1.0.4</p>
<p dir="auto">python-magic==0.4.12</p>
<p dir="auto">pytz==2018.3</p>
<p dir="auto">redis==2.10.6</p>
<p dir="auto">requests==2.20.0</p>
<p dir="auto">rsa==4.0</p>
<p dir="auto">simplejson==3.11.1</p>
<p dir="auto">six==1.12.0</p>
<p dir="auto">SQLAlchemy==1.2.5</p>
<p dir="auto">SQLAlchemy-Utils==0.33.1</p>
<p dir="auto">tld==0.7.9</p>
<p dir="auto">tornado==5.1.1</p>
<p dir="auto">uhashring==0.8</p>
<p dir="auto">Unidecode==0.4.21</p>
<p dir="auto">urllib3==1.24.1</p>
<p dir="auto">vine==1.3.0</p>
<p dir="auto">virtualenv==16.6.0</p>
<p dir="auto">virtualenv-clone==0.5.3</p>
<p dir="auto">voluptuous==0.11.1</p>
<p dir="auto">Werkzeug==0.14.1</p>
<p dir="auto">WooCommerce==1.2.1</p>
<p dir="auto">zipp==0.6.0</p>
</details>
<h3 dir="auto">Celery report</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:4.3.0 (rhubarb) kombu:4.6.4 py:3.6.5
            billiard:3.6.1.0 py-amqp:2.5.1
platform -&gt; system:Linux arch:64bit
            kernel version:4.15.0-58-generic imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:amqp results:disabled

broker_url: 'amqp://guest:********@localhost:5672//'"><pre class="notranslate"><code class="notranslate">software -&gt; celery:4.3.0 (rhubarb) kombu:4.6.4 py:3.6.5
            billiard:3.6.1.0 py-amqp:2.5.1
platform -&gt; system:Linux arch:64bit
            kernel version:4.15.0-58-generic imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:amqp results:disabled

broker_url: 'amqp://guest:********@localhost:5672//'
</code></pre></div>
<h3 dir="auto">Similar issues:</h3>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="97457005" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/2727" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/2727/hovercard" href="https://github.com/celery/celery/issues/2727">#2727</a></p>
<p dir="auto">[2015-07-27 12:52:38,386: ERROR/MainProcess] Task myapp.tasks.test [150a75dc-592e-4c0c-b686-1cc5aaf5a168] raised unexpected: Terminated(15,)<br>
Traceback (most recent call last):<br>
File "/home/blake/projects/venv/myapp/lib/python2.7/site-packages/billiard/pool.py", line 1674, in _set_terminated<br>
raise Terminated(-(signum or 0))<br>
Terminated: 15</p>
<p dir="auto">packages installed:</p>
<p dir="auto">amqp==1.4.6<br>
anyjson==0.3.3<br>
beautifulsoup4==4.4.0<br>
billiard==3.3.0.20<br>
celery==3.1.18<br>
Django==1.7.7<br>
django-celery==3.1.16<br>
django-pipeline==1.5.2<br>
futures==3.0.3<br>
kombu==3.0.25<br>
pytz==2015.4<br>
redis==2.10.3<br>
requests==2.7.0<br>
wheel==0.24.0</p>
<p dir="auto">I'm starting worker with:</p>
<p dir="auto">celery -A myapp worker --loglevel=INFO --concurrency=10</p>
<p dir="auto">i'm revoking with:</p>
<p dir="auto">from celery.task.control import revoke<br>
revoke(task_id, terminate=True, signal='SIGKILL')</p>
<p dir="auto">is this the wrong approach?</p>