Skip to content

Instantly share code, notes, and snippets.

@mzaradzki
Last active May 16, 2018
Embed
What would you like to do?
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