Using Flask web app as Windows application
<p>We have a web application developed using Flask that runs on a Windows server with clients that connect to it.  We now have a use case where it is desired that the server and client be combined onto a laptop so that both server and client code run together and make it appear as a native Windows application.</p>

<p>Basically, we now have two requirements that we did not have before:
1. Must be able to launch the browser from within Python.
2. Must be able to terminate the Python (Flask) application on browser window close.</p>

<p>We have succeeded in item 1.  Item 2 remains elusive.  We have tried terminating the werkzeug server but the Python code keeps running.  Seeking help from those that know.</p>

<p>I do not currently have a Windows client here so I cannot exactly test what I am suggesting.</p>

<p>Using <strong>pywinauto</strong> you can check for a Window's name.</p>

<p>You could build a script that checks this in background and kills your Flask application when the requested browser window is not opened.</p>

<pre><code>from pywinauto.findwindows import find_windows
if not find_windows(best_match='YOURWINDOWNAMEHERE'):
    # Do your kill
</code></pre>

python flask