Gunicorn部署django报异常 server closed the connection unexpectedly

在使用Gunicorn部署Django时遇到'服务器意外关闭连接'的异常,该问题可能由于设置max-request参数导致在数据库操作期间Gunicorn重启子worker。解决方案是在操作model前检查数据库连接,例如参考解决Django MySQL超时的博客进行处理。
摘要由CSDN通过智能技术生成

1.启动Django

数据库采用postgres,驱动psycopg2

gunicorn --certfile=XXXX --keyfile=XXXX  --max-request 50 --max-requests-jitter 50 application.wsgi -c gunicorn_conf.py

2.异常信息

server closed the connection unexpectedly。

详细信息:

This probably means the server terminated abnormally before or while processing the request.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py",line 8
return self.cursor.execute(sql,params)
psycopg2.OperationalError:server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.

3.可能触发原因

设置max-request为某个数值,gunicorn将重新启动子worker,导致使用djangomodel读取数据库时就会报错。

4.解决方案

在使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值