Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from time import localtime, mktime
MAX_RUN_MINUTES = 120
def cron_killer():
def __run_minutes(proc):
t_start = localtime(proc.create_time())
t_now = localtime()
return (mktime(t_now) - mktime(t_start)) / 60.
for proc in __get_cron_processes():
if __run_minutes(proc) > MAX_RUN_MINUTES:
if proc.status() in ['sleeping', 'zombie']: # you may want to kill long running processes too
for sub_proc in proc.children(recursive=True):
sub_proc.kill()
proc.kill()
else:
None # keep running
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment