Flask includes a built-in development server, which supports non-production use.
We'll show you how to run your application continuously with that server.
-
First, ensure that your Flask app starts from the command line and works as expected.
If Flask doesn't work at this point, it won't work with AlwaysUp either!
For this tutorial, we deployed a simple web application in "C:\web\projects\testproject". The code is in a file named
"time-server.py":
Notice that Flask created the ".venv\Scripts" sub-folder (which contains the executable files) as part of the installation process:
With this configuration, here is the full command line we use to run our application from a command prompt:
C:\web\projects\testproject\.venv\Scripts\flask.exe --app time-server run
Note that the command must run from the "C:\web\projects\testproject" folder so that it can find the time-server python script.
Otherwise, we'd have to specify the full path to the .py file in the command line.
In any case, we verified that our command line started Flask and the simple application worked as expected:
-
Download and install AlwaysUp, if necessary.
-
Start AlwaysUp.
-
Select Application > Add to open the Add Application window:
-
On the General tab:
-
In the Application field, enter the full path to the Flask executable, flask.exe.
This will likely reside in the ".venv\Scripts" sub-folder where you deployed your Flask app.
-
In the Arguments field, enter the parameters for your command line that starts your Flask application (from step #1).
-
In the Start in directory field, enter the folder where you deployed your Flask application.
-
In the Start the application field, select Automatically, but shortly after the computer boots.
This setting — which delays Flask by about 2 minutes after a reboot — should ensure that critical system services
(like networking and security) are ready and waiting when Flask starts automatically with Windows.
-
And in the Name field, enter the name that you will call the application in AlwaysUp.
We have used Flask app but feel free to specify a different name if you like.
-
Move to the Logon tab and enter the user name and password of the Windows account where you installed Python and Flask.
-
We're done configuring Flask so click the Save button to record your settings.
In a couple of seconds, an entry named Flask app (or whatever you called it) will show up in the AlwaysUp window.
It is not yet running though and its state will be "Stopped":
-
To start Flask, choose Application > Start "Flask app".
The state should soon transition to "Running" and Flask will be working in the background:
And with Flask running as a Windows Service, please confirm that your Flask app is available from your browser.
Everything looked good on our system:
-
That's it! Next time your computer boots, your Flask application will start up immediately, in the background, without anyone needing to log on.
Please restart your PC now and test that everything works as expected after Windows comes back to life.
And please feel free to edit Flask in AlwaysUp and explore the many other settings that may be appropriate for your environment.
For example, send an email if Flask stops, boot priority to give it more CPU, or recycle it weekly to cure memory leaks.