Forums

Restart Web App from Python (for web api)

I want to make a web api using flask. When i call mysite.pythonanywhere.com/api/restart i want to run a command via os.system.

In Example: os.system("service webapp restart")

But the example won't work - sure! What is the right command to do that?

you can try a subprocess.call with touch var/www/<your-site-wsgi-file>

I am a bit scared to ask why you are restarting your webapp over a web api... :D

I develop my app right on pythonanywhere - not local. I have some variables that i want to have after restarting the web app. I save them in a file and after restart i read the file into the varianles. But copying the variables into files and changing to dashboard and changing to web and clicking restart web app is too much for me. So i want to restarr the web app and copy data when calling the api. Feel free to ask more :D

And thank you fkr your answer. I'll try it today...

Why not just keep the web tab open in a separate tab to the one you're working in? Then you can just ctrl+page-up and ctrl+pagedown to it, hit reload, get back to your work, shouldn't take too long?

Yeah, but copying the varianlea into files and then changing... es too much for me. I make a local py script that executes my api when clicking on a button and that's all. This is what i would like to have ;)

Simply touch doesn't work. What does the server do when i click on reload web app im my dashboard? I just want to do this.

Touch definitely should work. The reload web app button does a lot of back-end processing on files outside your filesystem, so it's not something you can do from within your account.

Are you sure you're touching the right file? What's the exact command you're running?