问题
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')
or
sqlalchemy.exc.OperationalError: (OperationalError) (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") None None
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 ---
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.
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
What can I do? Thanks.
回答1:
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
来源:https://stackoverflow.com/questions/25904817/ningx-uwsgi-python-permanent-mysql-error-after-some-time-from-starting-applica