Python – why cpulimit makes process STOPPED

processpython

I'm running a python script which uses networkx package to run some algorithms on graphs.

the script is

import networkx as nx
from networkx.algorithms.approximation import clique

G = nx.read_adjlist("newman_one_mode.adj")
print "the number of nodes in the graph is: " + str(G.number_of_nodes())
max_clique_nodes = clique.max_clique(G)
print "the clique nodes are: " + str(max_clique_nodes)

It takes a long time and has high cpu usage (99%), so I want to limit its cpu usage.

I used cpulimit on this process to limit the cpu usage to 60%

cpulimit -p 29780 -l 60

however, when I use it, the process got STOPPED, as below

[lily@geland academic]$ python run.py
the number of nodes in the graph is: 16264

[1]+  Stopped                 python run.py

what is wrong and how to deal with such situations?
thanks!

side information:
if I don't run cpulimit, the process runs for a long time and then got killed, I don't know why, maybe it is due to resource being used up.

[lily@geland academic]$ python run.py
the number of nodes in the graph is: 16264
[1]+  Terminated              python run.py
Killed

Best Answer

That's expected behavior.

cpulimit suspends the process when it consumes too much CPU resource and resume the process after a certain amount of time.

Also check if your script is waiting for input? If so, your script will enter a stopped state as well.

Try redirect stdin and run cpulimit again, e.g python run.py < /dev/null &

Related Question