Created
May 15, 2018 10:29
-
-
Save mzaradzki/5e042581a8af4a7d4363e6cfb328c550 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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