I'm using PythonDjango with Celery and Redis and I want to catch two erros:
OperationalError
means the server is down Functionality:
OperationalError
it should check also app.control.inspect().active()
OperationalError
it shouldn't check app.control.inspect().active()
because Celery will hang/freeze Code:
if not error:
try:
send_email_task.delay(subject=subject, ..., html_content=html_content)
except OperationalError as e:
# do something
if not app.control.inspect().active():
# do something
else:
......
My issue, if I have an OperationalError
the condition if not app.control.inspect().active()
will hang the code
If I add the code app.control.inspect().active()
inside try
will hang/freeze, will indefinitely check status if is an OperationalError
.
Looks like you need the else
block in try-catch
Try:
if not error:
try:
send_email_task.delay(subject=subject, ..., html_content=html_content)
except OperationalError as e:
# do something
else:
if not app.control.inspect().active():
# do something
else:
......
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.