python连接池interfaceerror_关于python:InterfaceError:连接已经关闭(使用django + celery + Scrapy)...

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值