A
A
Andrey Shirshov2016-11-06 16:00:01
Flask
Andrey Shirshov, 2016-11-06 16:00:01

How to reload Flask with a site request?

Good afternoon.

On Flask-plugins, I saw an example code of how you can restart the server by clicking on a button on the site. An example for Linux, but I will need it to work on Windows in addition to Linux.
According to the answers on Stackoverflow, the following is obtained:

@app.route('/restart')
def restart_flask():
    args = [sys.executable] + sys.argv[:]
    os.execv(sys.executable, args)
    return("")

But it doesn't work. The Python.exe process crashes. I can't even figure out why...

There is also an interesting Livereload project that automatically reloads flask when .py, .html and probably .css files change. I tried to understand the code, but have not yet figured out how he manages to reload flask.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2016-11-06
@deliro

You configure uwsgi to reboot via touch (touch-reload).
You call touch in the view.
PROFIT

A
Andrey Shirshov, 2016-11-06
@sindzicat

I found that LiveReload has some issues when running on Windows. In particular, Flask does not always reload. Sometimes Python.exe crashes.
I have decided that this feature will only be used in the web version that will run on Linux. And under Windows it will no longer be flask, but something else. Accordingly, my question is no longer relevant.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question