Forums

Long running tasks as scheduled and in console

I have a script that I always want to be running and I run it in the console because it tends to run faster than as a scheduled task. I followed the Long Running Task guide https://help.pythonanywhere.com/pages/LongRunningTasks/ here and I have scheduled tasks that run in case the console script crashes.

However now I run two instances of the same script. Is there a way for the scheduled tasks to not run if it is running in the console?

The better solution would just have the script running forever in the console...but it does crash sometimes.

The code on the Long running tasks page only works if the 2 processes are on the same machine, so it won't work between task and console servers and won't necessarily work between different consoles.

You could implement a similar locking mechanism using the file system which is shared between machines but then you'd have to be very careful about handling crashes so you don't end up with the lock hanging around.