问题描述
我将nginx用作前端服务器,并将uwsgi用于python应用程序.大约一天一次,我的一个应用程序开始下降.在日志中,我可以看到不同的mysql错误.例如:
I'm using nginx as frontend server and uwsgi for python applications. About one time a day one of my applications starts falling. In log I can see different mysql errors. For example:
sqlalchemy.exc.OperationalError: (OperationalError) (2006, 'MySQL server has gone away')
或
sqlalchemy.exc.OperationalError: (OperationalError) (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") None None
还有关于can't locate row column for column ...
的信息.也许更有趣:
Also there were something about can't locate row column for column ...
. And maybe more interesting:
--- no python application found, check your startup logs for errors ---
有什么帮助-我正在杀死uwsgi进程,然后再次运行它.有趣的是,其他应用程序(它们也使用mysql)都可以正常运行,并且可以继续工作.
What help's - I'm killing my uwsgi process and run it again. Interesting thing is other apps (they also use mysql) are ok and continue to work.
如果我只是杀死叉子,那什么也没发生.我必须杀死主进程.
If I just kill forks nothing happens. I must kill master process.
我的uwsgi配置为:
My uwsgi config is:
module = stulyev
callable = app
pp = /home/krasulya/apps/stulyev.net
logto = /var/log/stulyev.net.log
touch-reload = /tmp/stulyev.net.sock
socket = /tmp/stulyev.net.sock
uid = krasulya
gid = www-data
daemonize = /var/log/stulyev.net.daemon.log
reload-on-exception = true
harakiri = 30
max-requests = 10000
harakiri-verbose = 1
buffer-size = 65535
我该怎么办?谢谢.
推荐答案
请勿在主数据库中打开数据库连接.并非所有的sqlalchemy适配器都支持它.每个工作者一次打开连接,或向uWSGI添加lazy-apps = true以便在每个分支上加载整个应用程序: http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html
Do not open the database connection in the master. Not all sqlalchemy adapter supports it. Open the connection one time per worker or add lazy-apps = true to uWSGI to load the whole app at every fork: http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html
这篇关于从启动应用程序一段时间后,ningx,uwsgi,python永久mysql错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!