High Kernel CPU when running multiple python programs High Kernel CPU when running multiple python programs linux linux

High Kernel CPU when running multiple python programs


If the problem exists in kernel, you should narrow down a problem using a profiler such as OProfile or perf.

I.e. run perf record -a -g and than read profiling data saved into perf data using perf report. See also: linux perf: how to interpret and find hotspots.


In your case high CPU usage is caused by competition for /dev/urandom -- it allows only one thread to read from it, but multiple Python processes are doing so.

Python module random is using it only for initialization. I.e:

$ strace python -c 'import random;while True:    random.random()'open("/dev/urandom", O_RDONLY)     = 4read(4, "\16\36\366\36}"..., 2500) = 2500close(4)                                   <--- /dev/urandom is closed

You may also explicitly ask for /dev/urandom by using os.urandom or SystemRandom class. So check your code which is dealing with random numbers.