简体   繁体   中英

How to monitor changes in a WSGI Flask application?

I am designing a very simple web GUI for my raspberry pi.

At the same time, I'm learning about WSGI and Flask applications. Since I'm on raspberry pi, I'd like to stick to my apache server and use WSGI over the Flask server (which I don't know at all but should look into some day).

I saw that Flask applications need a touch call on the wsgi script for the flask daemon to rebuild the whole application, see here for instance. However, when developping, I find this a very annoying feature.

The ReloadingSourceCode wiki gives a piece of code that claims to remove this limitation. (Anchor is broken, search for " Monitoring_For_Code_Changes ". Code formatting seems broken too...)

Though, this seems to apply to a bare WSGI applications only.

If this is also adapted to Flask applications, where should I put the code?

If it it not, is there any other way I could remove the "touch" thing?

I'm not sure you'd want this on anything but a private project (like i'm assuming your RPi is), but I used the code below on a private/login_required route in my interface.

Perhaps not pretty, but does the job for me.

@app.route("/reload")
@login_required
def reload():
    import signal
    os.kill(os.getpid(), signal.SIGINT)
    flash(f'Reloaded at {str(datetime.now().strftime("%-I:%M %p"))} ')
    return redirect(url_for("home"))

I used the 'flash' message just to check it occurred when it redirects home - but leave this out if not required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM