title: Flask server unresponsive port - how to kill all threads
body: <p>I am running a Flask powered server in Python. The server has several POST and GET routes. Everything works fine for many days, then suddenly it becomes unresponsive from the point of view of the client, i.e. from the client side it looks like the server is unreachable or not running. Looking at the server side everything seems running normally. I suspect that at the OS level (Windows server 2012) a TCP socket may go bad but I do not get any exception notification on the server. To try and escape this status I have added a heartbeat POST, and server side a periodic scheduled check every 2 minutes that there is a fresher heartbeat coming from the client. If that is not the case (i.e. stale heartbeats) then my idea was to kill all threads serverside (a CTRL-C generated from within the python code) and then restart it externally via the launching script. This is what I followed to kill the server: <a href="http://flask.pocoo.org/snippets/67/" rel="nofollow noreferrer">http://flask.pocoo.org/snippets/67/</a> However at the first occurrence of the  "unreachable" state it looks like also the GET/POST route from localhost is now unresponsive. So the shutdown never gets triggered. </p>
  
  <p>Now my question: is there a way from a scheduler spawned thread to kill all other threads, including the Flask app.run thread? </p>
  
  <p>Many thanks! </p>
  
  <p>PB</p>