Skip to content

Instantly share code, notes, and snippets.

@mzaradzki
Last active May 16, 2018 07:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mzaradzki/8964aeddfed1f5437fcdbe3a77f9b03e to your computer and use it in GitHub Desktop.
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