How to limit I/O consumption of Python processes (possibly using ionice)?
psutil exposes this functionality (python 2.4 -> 3.2):
import psutil, osp = psutil.Process(os.getpid())p.ionice(psutil.IOPRIO_CLASS_IDLE)
Also, starting from Python 3.3 this will be available in python stdlib as well:http://bugs.python.org/issue10784
Hm.
As a start pointer, you should find what syscall
number are the ioprio_set
and ioprio_get
system calls in your kernel. I'd suggest you check in /usr/include/asm/unistd_32.h
or /usr/include/asm/unistd_64.h
, depending on your kernel arch; if not there, start with the suggestion of the syscall(2)
man page, which should be /usr/include/sys/syscall.h
and work your way down includes.
Given that, you should use ctypes
, à la:
def ioprio_set(which, who, ioprio): rc= ctypes.CDLL('libc.so.6').syscall(289, which, who, ioprio) # some error checking goes here, and possibly exception throwing
That's it, more or less. Have fun :)
Why not have whatever launches the processes do the ionice on them (i.e., run them with ionice) rather than having them ionice themselves? It seems a whole lot cleaner.