I created a web server by Django + uWSGI. The basic flow is: when a request is received, Django will initiated a sub thread by python build-in lib "Threading" to write db asynchronously, and in main thread it will respond immediately back to client.
How, uWSGI sometimes will respawn the worker process(maybe when there is no request handling by the process?), which caused the background sub thread is also killed even when it's not finished yet. Any clue to avoid uWSGI not to respawn a worker process which has a running sub-thread?
uWSGI respawn log:
DAMN ! worker 4 (pid: 31161) died, killed by signal 9 :( trying respawn ...
# Django's wsgi file
wsgi-file = /home/fh/dj_uwsgi/dj_site/dj_site/wsgi.py
master = true
processes = 10
http = :8001
threads = 2
enable-threads = true
http-timeout = 10
max-requests = 5000
chmod-socket = 664
vacuum = true
pidfile = /home/fh/dj_uwsgi/dj_site/uwsgi.pid
daemonize = /home/fh/log/uwsgi_dj.log
daemon = True
# actions to write db
my_sub_thread = SubThreadClass()
from handlers import myHandler
Manually dealing with threads is rarely a good idea in an environment you do not manage.
You should use an offline worker system like Celery.