Score:0

How to keep a Python app running?

id flag

My problem is that i want to keep a Python app running, but it stops every 2-3 days. Is there a way to autorestart the .py when it stops. Is there a way to monitor that? Probably there is but i can't find it.

Thanks for the help.

Score:4
am flag

There really isn't any reason why a python app should suddenly stop running. I would suggest looking into why it stops (crash, out of memory, ...) and trying to solve that.

If you really just want to restart it tough it depends on how you start it in the first place.

If you for example start it as a systemd service you should set the Restart=on-failure property in your systemd unit file.

If you just start it using the commandline you can use a simple bash loop:

while true
do
    python file.py
done
ComputerBas avatar
id flag
Thank you very much! I did the Restart=on-failure option. I guess i have to wait a few days to see if it's really keeping the app running. :)
ComputerBas avatar
id flag
The app did not start correctly. So i did the second option. Worked for me!! And BTW it's an app that scans websites on demand but some sites make the app crash. That's why ;)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.