Forums

I want to kill previous running scheduled task before run same scheduled task.

Hello.

I want to run only one python script every hour. So I set up task to run hourly in schedule tab. But after few hours, there are many same running tasks in 'Running scheduled tasks' field.

I want to kill previous running scheduled task before run same scheduled task. How can I do that?

Have a nice day.

That's possible, but non-trivial (there are probably different ways you could do it, the first one that occurs to me is storing the pid of each task from os.getpid() and saving it to a file, and then use os.kill(pid) at the beginning of your task. but you'd have to deal with edge cases...)

The alternative is to have some code that just exits early if it spots your task from the previous hour is still running? If that could work for you, there's an example here: https://help.pythonanywhere.com/pages/LongRunningTasks

Thank you for detailed answer. I'll try it.

I use os module and it works. Thanks!

Great! Thanks for confirming :-)