Utility functions¶
check_parens(decorator)
¶
Check whether or not a decorator function gets called with parens:
- If called with parens, the decorator is called without the function as the first argument, but necessarely with decorator keyword arguments.
- If called without parens, the decorator is called with the function as the first argument, and the decorator's default arguments.
This function is used internally to endow every decorator of the above property.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decorator |
F
|
decorator to wrap |
required |
Returns:
Type | Description |
---|---|
F
|
Wrapped decorator. |
Usage:
@check_parens
def decorator(func, k1="default1", k2="default2"):
# where the magic happens
...
# `decorator` called without parens, hence default params.
@decorator
def func(*func_args, **func_kwargs):
pass
# `decorator` called with custom params, necessarely using parens.
@decorator(*args, **kwargs)
def func(*func_args, **func_kwargs):
pass
Source code in deczoo/_utils.py
_get_free_memory()
¶
Computes machine free memory via /proc/meminfo
file (linux only).
Warning
This functionality is supported on unix-based systems only!