python连接池interfaceerror

562次阅读
没有评论
python连接池interfaceerror

Unfortunately this is a problem with django + psycopg2 + celery combo.

It's an old and unsolved problem.

Take a look on this thread to understand:

https://github.com/celery/django-celery/issues/121

Basically, when celery starts a worker, it forks a database connection

from django.db framework. If this connection drops for some reason, it

doesn't create a new one. Celery has nothing to do with this problem

once there is no way to detect when the database connection is dropped

using django.db libraries. Django doesn't notifies when it happens,

because it just start a connection and it receives a wsgi call (no

connection pool). I had the same problem on a huge production

environment with a lot of machine workers, and sometimes, these

machines lost connectivity with postgres server.

I solved it putting each celery master process under a linux

supervisord handler and a watcher and implemented a decorator that

handles the psycopg2.InterfaceError, and when it happens this function

dispatches a syscall to force supervisor restart gracefully with

SIGINT the celery process.

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:Python基础教程2022-11-22发表,共计929字。
新手QQ群:570568346,欢迎进群讨论 Python51学习