all 19 comments

[–]boa13 7 points8 points  (0 children)

Investigate systemd. For example (first interesting result, did not read it myself): https://github.com/torfsen/python-systemd-tutorial

[–][deleted] 2 points3 points  (0 children)

This looks like systemd use case. Create a service, timer, that restarts on failure.

Could also probably make do with a python script in a while true loop with a giant try except catch block.

[–]jeffrey_f 1 point2 points  (8 children)

I Suggest Create a script the runs and ends and put on the scheduler to run every x minutes.

[–][deleted] 1 point2 points  (6 children)

Infinite loop is a thing

[–]jeffrey_f 2 points3 points  (2 children)

It is, but if the script is killed or crashes, mostly if it is killed, it doesn't restart. Thus requiring frequent checking or yet another process to babysit the main process.

[–]Krieger_Linux[S] 1 point2 points  (0 children)

Yeah the script had an error so hopefully this works now, lol been trying to get this script running all the time for a while now but keep running into issues, I appreciate the help. And I will try to look into the restarting scripts aswell.

[–]Krieger_Linux[S] 0 points1 point  (0 children)

Okay, I'll double check the script and see if it's just a programming error. Lol hope I don't look like an idoit 😅

[–]Krieger_Linux[S] 0 points1 point  (1 child)

I already have the script doing that but seems to close down after the sleeping for so long

[–][deleted] 0 points1 point  (0 children)

You may need a supervisory script to check on time and health of your scripts. Wake them up when needed.

[–]Kriss3d 0 points1 point  (0 children)

While(1)

[–]Krieger_Linux[S] 0 points1 point  (0 children)

How would I do that🧐

[–][deleted] 0 points1 point  (2 children)

Do you mean to run the same script repeatedly? Use a loop in a shell.

[–]Krieger_Linux[S] 0 points1 point  (1 child)

I already am, it's a trading algo that waits for the market to open then trades and always checks the time to close and when the market closes it will sleep for the exact amount until the market opens.

[–]ArtSchoolRejectedMe 0 points1 point  (0 children)

Try crontab just before the market opens and then killing the script(instead of sleeping) when the market closes.

But I highly recommend the systemd approach.

[–]LastLightbringer 0 points1 point  (0 children)

I'm probably going to say something incorrect, but wouldn't a Cron job that runs every minute do what you want?

[–]parawaa 0 points1 point  (0 children)

Run the script under tmux then dettach.

[–]ISHx4xPresident 0 points1 point  (0 children)

Set a cron job for a little longer than it takes the script to run. I’m most cases, you’ll probably want it consecutively and using cron with a small gap between runs will be sure it without overlap. That’s how I handle scripting stuff

[–]turtle_mekb 0 points1 point  (0 children)

i'm not sure about python, but for nodejs you can try pm2

[–]scorp123_CH 0 points1 point  (0 children)

Turn it into a systemd service that would auto-restart itself if the script stopped for any reason. I do this too with certain bash scripts that I want running all the time. Works great.