title: How to avoid Django sub thread being killed by uWSGI respawn
body: <p>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. </p>
  
  <p>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?</p>
  
  <p>uWSGI respawn log:</p>
  
  <pre><code>DAMN ! worker 4 (pid: 31161) died, killed by signal 9 :( trying respawn ...
  </code></pre>
  
  <p>uWSGI ini config (version 2.0.12):</p>
  
  <pre><code>[uwsgi]
  # 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
  </code></pre>
  
  <p>Django(version 1.8) app pseudo code:</p>
  
  <p>in handlers.py:</p>
  
  <pre><code>import threading
  
  class SubThreadClass(threading.Thread):
      daemon = True
  
      def run(self):
          # actions to write db
  
  def myHandler():
      my_sub_thread = SubThreadClass()
      my_sub_thread.start()
  </code></pre>
  
  <p>in views.py:</p>
  
  <pre><code>from handlers import myHandler
  
  def url_handler(request): 
      myHandler()
      return HttpResponse()
  </code></pre>