You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If i run celery with '-P eventlet' option i cannot catch CalledProcessError raised by subprocess.check_output inside the task
function. I only can catch general Exception class exception instead.
PS. maybe it's somehow related with exceptions serialization?
PSS. works with '-P gevent'
celery -A task worker --loglevel=info
>>> from task import test
>>> test.delay()
<AsyncResult: eca78f41-8242-465d-b996-dc8b39144f3b>
the output is:
[2017-06-01 09:23:37,379: INFO/MainProcess] Connected to redis://localhost:6379/0
[2017-06-01 09:23:37,385: INFO/MainProcess] mingle: searching for neighbors
[2017-06-01 09:23:38,400: INFO/MainProcess] mingle: all alone
[2017-06-01 09:23:38,405: INFO/MainProcess] celery@localhost ready.
[2017-06-01 09:24:33,734: INFO/MainProcess] Received task: task.test[eca78f41-8242-465d-b996-dc8b39144f3b]
[2017-06-01 09:24:33,738: WARNING/PoolWorker-4] caller process exception
[2017-06-01 09:24:33,738: WARNING/PoolWorker-4] <class 'subprocess.CalledProcessError'>
[2017-06-01 09:24:33,738: INFO/PoolWorker-4] Task task.test[eca78f41-8242-465d-b996-dc8b39144f3b] succeeded in 0.0037605260004056618s: None
2nd case
if i run:
celery -P eventlet -A task worker --loglevel=info
>>> from task import test
>>> test.delay()
<AsyncResult: 871fc6b7-1a2a-4b02-94a4-c0f3fe3f5eac>
the output is:
[2017-06-01 09:25:11,538: INFO/MainProcess] Connected to redis://localhost:6379/0
[2017-06-01 09:25:11,543: INFO/MainProcess] mingle: searching for neighbors
[2017-06-01 09:25:12,556: INFO/MainProcess] mingle: all alone
[2017-06-01 09:25:12,560: INFO/MainProcess] celery@localhost ready.
[2017-06-01 09:25:12,566: INFO/MainProcess] pidbox: Connected to redis://localhost:6379/0.
[2017-06-01 09:25:15,325: INFO/MainProcess] Received task: task.test[871fc6b7-1a2a-4b02-94a4-c0f3fe3f5eac]
[2017-06-01 09:25:15,328: WARNING/MainProcess] general exception
[2017-06-01 09:25:15,328: WARNING/MainProcess] <class 'subprocess.CalledProcessError'>
[2017-06-01 09:25:15,329: INFO/MainProcess] Task task.test[871fc6b7-1a2a-4b02-94a4-c0f3fe3f5eac] succeeded in 0.0034008210022875573s: None
3d case: if raise CalledProcessError manually
from celery import Celery
from celery import Task
import subprocess
from subprocess import CalledProcessError
app = Celery('task', broker='redis://localhost:6379/0')
@app.task()
def test():
try:
raise CalledProcessError(1, 'test')
except CalledProcessError as cpe:
print('caller process exception')
print(type(cpe))
print(cpe)
except Exception as e:
print('general exception')
print(type(e))
print(e)
if i run:
celery -P eventlet -A task worker --loglevel=info
>>> from task import test
>>> test.delay()
<AsyncResult: 4ef2d70e-e6f5-4fa0-87e6-8a996be84bde>
Everything works as i expected:
[2017-06-02 11:15:07,852: INFO/MainProcess] Connected to redis://localhost:6379/0
[2017-06-02 11:15:07,858: INFO/MainProcess] mingle: searching for neighbors
[2017-06-02 11:15:08,873: INFO/MainProcess] mingle: all alone
[2017-06-02 11:15:08,883: INFO/MainProcess] celery@localhost ready.
[2017-06-02 11:15:08,884: INFO/MainProcess] pidbox: Connected to redis://localhost:6379/0.
[2017-06-02 11:15:11,874: INFO/MainProcess] Received task: task.test[4ef2d70e-e6f5-4fa0-87e6-8a996be84bde]
[2017-06-02 11:15:11,875: WARNING/MainProcess] caller process exception
[2017-06-02 11:15:11,875: WARNING/MainProcess] <class 'subprocess.CalledProcessError'>
[2017-06-02 11:15:11,875: WARNING/MainProcess] Command 'test' returned non-zero exit status 1.
[2017-06-02 11:15:11,875: INFO/MainProcess] Task task.test[4ef2d70e-e6f5-4fa0-87e6-8a996be84bde] succeeded in 0.000474446002044715s: None
Expected behavior
subprocess.CalledProcessError - caugth in both cases
Actual behavior
subprocess.CalledProcessError - caugth in 1st case
subprocess.CalledProcessError - no exception trails in 2nd case
Exception class - caugth in 2nd case, but the printed class is <class 'subprocess.CalledProcessError'>
The text was updated successfully, but these errors were encountered:
Celery/deps version:
amqp==2.1.4
appdirs==1.4.3
Babel==2.4.0
billiard==3.5.0.2
celery==4.0.2
enum-compat==0.0.2
eventlet==0.21.0
flower==0.9.1
greenlet==0.4.12
kombu==4.0.2
packaging==16.8
pyparsing==2.2.0
pytz==2017.2
redis==2.10.5
six==1.10.0
tornado==4.2
vine==1.1.3
python version is 3.6
Problem description:
If i run celery with '-P eventlet' option i cannot catch CalledProcessError raised by subprocess.check_output inside the task
function. I only can catch general Exception class exception instead.
PS. maybe it's somehow related with exceptions serialization?
PSS. works with '-P gevent'
Task code:
https://gist.github.com/vitenbergd/8fc8d3bb87219c871b854def667929c4#file-task-py
Steps to reproduce
1st case:
f i run:
the output is:
2nd case
if i run:
the output is:
3d case: if raise CalledProcessError manually
if i run:
Everything works as i expected:
Expected behavior
subprocess.CalledProcessError - caugth in both cases
Actual behavior
subprocess.CalledProcessError - caugth in 1st case
subprocess.CalledProcessError - no exception trails in 2nd case
Exception class - caugth in 2nd case, but the printed class is <class 'subprocess.CalledProcessError'>
The text was updated successfully, but these errors were encountered: