Forums

Autoreload Flask app?

hi all,

google says if you use the built-in python/flask web server you just say "app.run(debug=True)" and the app will auto-reload any time it is changed -- which is awesome.

can that be done with PythonAnywhere?

previous posts seem to say 'no' but....my main reason for looking for a platform like this is to be able to prototype things quickly, so that functionality or similar is a must.

thanks.

You can touch your wsgi.py file at /var/www/

Of course, you don't want to auto-reload for a production site.

Thanks, I had read about the 'touch' option, but I want something automatic.

I think I'll try to set a prompt_command and see if that does it:

PROMPT_COMMAND+="touch /var/www/my-wsgi.py;"

will update when i see what happens.

thanks.

ok, tried.

honestly can't tell if it works or not. if it does, it's very unreliable.

but i also realized i don't want it to run on every command prompt -- b/c then i'd actually have to leave vi -- i want it to run every time one of my app files changes.

so, dead end for now. could be an interesting platform if it could be used for at least dev.

If you are using vim why not just touch it on bufwrite?

There is also a couple seconds of delay when it comes to syncing across servers etc. (where you are writing on vim may be different from where your webapp is hosted, so it will need to realize wsgi.py was touched and then reload)

Also keep in mind that for static file changes/template changes etc, you can see the changes without reloading.

thanks for the tip, i tried it and it works.

seems to take about 10 seconds for the server to restart or whatever it needs to do. which I'd like to cut down to about 1 second or less.

this is what i appended to my .vimrc -- not sure what all was necessary, but i didn't want cruft showing up in the editor, etc., and this syntax seems to have solved it.

autocmd BufWritePost * silent! !touch /var/www/shmooth_pythonanywhere_com_wsgi.py >/dev/null 2>&1

i'm only on the free plan -- i'd pay something to be able to run in test/debug mode and have my app refresh quickly.

i don't need distributed whatever while i'm doing dev. i do need a fast dev cycle.

Hmm. Not sure if there's a very good way to get to <10s reliably.

The way I do it is to write and run unittests on the same server (easiest is probably to use tmux), so it's a fast feedback cycle. vs say every hr or so I'm reloading/looking at the actual webapp.