Forums

How to Kill and start a new task

I have a python file which I would love to run on task every hour, but when I start the task, it runs with same multiple running task consuming much CPU speed. I would love to kill the previous running task before starting new task so that I will have only I unique task running.

I did this

import signal import os pid=os.getpid() os.kill(pid, signal.SIGTERM)

my program codes follows below

This terminates the task but doesn't run the codes below to start a new task

How can I achieve this. Thanks in anticipation

The code you have kills the current process. It will not kill the previously run task. If you want your task to complete, then just let it exit when it's done.