Skip to content

[Flask] Enhance guide with notes about restarting Flask #1887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions source/guide_flask.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.. author:: Benjamin Wießneth <[email protected]>
.. author:: Christian Macht <https://github.com/cmacht/>
.. author:: Barbara Shaurette <https://github.com/mechanicalgirl/>

.. tag:: lang-python
.. tag:: web
Expand Down Expand Up @@ -214,6 +215,52 @@ Flask is now running on the server, but because of Uberspace's :manual_anchor:`n
.. include:: includes/web-backend.rst


Restarting Flask
---------------------

When you deploy changes to your code, you may need to restart Flask in order to see those changes applied.

If you have deployed using ``rsync`` (see :lab:`Automatic Deployment with CI/CD <howto_automatic-deployment.html>`), the virtual Python environment where ``uwsgi`` was installed will probably have been overwritten. To verify, navigate to your project root and list the directory contents.

.. code-block:: console

[isabell@stardust ~]$ cd basic_flask
[isabell@stardust basic_flask]$ ls -l
-rw-r--r--. 1 isabell isabell 144 Mar 28 16:18 start.py
drwxr-xr-x. 1 isabell isabell 169 Mar 28 16:20 static
drwxr-xr-x. 1 isabell isabell 169 Mar 28 16:20 templates
-rw-r--r--. 1 isabell isabell 52 Mar 28 16:18 uwsgi.ini
[isabell@stardust ~]$

If you do not see your ``ENV`` folder, you will need to create it, then reinstall ``uwsgi`` and any other application dependencies.

.. code-block:: console

[isabell@stardust basic_flask]$ python3.11 -m venv ENV
[isabell@stardust basic_flask]$ source ENV/bin/activate
(ENV) [isabell@stardust basic_flask]$ pip install flask uwsgi
(ENV) [isabell@stardust basic_flask]$

Finally, restart the ``flask`` process with ``supervisorctl``.

.. code-block:: console

(ENV) [isabell@stardust basic_flask]$ supervisorctl restart flask
flask: stopped
flask: started
(ENV) [isabell@stardust basic_flask]$ supervisorctl status
flask RUNNING pid 28596, uptime 0:01:08
(ENV) [isabell@stardust basic_flask]$

.. note::

If you are using a deploy process that does not overwrite your virtual Python environment, use the ``touch-reload`` option in your ``~/basic_flask/uwsgi.ini``. This option reloads uWSGI if the specified file is modified/touched (this can be any file in your project root).

.. code-block:: ini

touch-reload = '/home/isabell/basic_flask/start.py'


Best Practices
==============

Expand Down