Last active
May 16, 2018 07:23
-
-
Save mzaradzki/8964aeddfed1f5437fcdbe3a77f9b03e 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 psutil import virtual_memory | |
from functools import wraps | |
MIN_VM_SHARE = 0.10 | |
MAX_CRON_PROCESSES = 5 | |
def cron_control(func=None): | |
@wraps(func) | |
def wrapped(*args, **kwargs): | |
vm = virtual_memory() | |
if vm.free < MIN_VM_SHARE * vm.total: | |
return None # virtual memory usage over limit | |
elif len(__get_cron_processes()) > MAX_CRON_PROCESSES: # strict inequality | |
return None # process count over limit | |
else: | |
return func(*args, **kwargs) | |
return wrapped |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment