You can write a decorator that updates the running process on entry and exit:
import os import functools def low_priority(f): @functools.wraps(f) def reniced(*args, **kwargs): os.nice(5) try: f(*args,**kwargs) finally: os.nice(-5) return reniced
Then you can use it as follows:
@low_priority def test(): pass
Denial of responsibility:
- Works on my machine, not sure how universal os.nice is.
- As indicated below, whether it works or not, it depends on your os / distribution or root.
- Nice works through the process. Behavior with multiple threads per process is probably not normal and could lead to a crash.
source share