I have the following CherryPy quickstart example:
import cherrypy
class HelloWorld(object):
@cherrypy.expose
def index(self):
return "Hello world!"
if __name__ == '__main__':
cherrypy.quickstart(HelloWorld())
I've found that if I leave it running, it is consistently near the top of the top
output. For example, I left it running over night (not 24 hours) and this is the line from top:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8284 pi 20 0 126212 13868 5792 S 7.2 3.1 112:51.88 python
And the server is not being interacted with over REST during this time, only idling. Any reason for this high CPU usage, or a workaround to prevent it?
It may be unrelated, but the below python code also uses a lot of CPU:
while True:
pass
It uses a lot more CPU (rightly so, maybe) but it makes me wonder if the CherryPy quickstart is doing something similar to wait behind the scenes.
I really don't think you should worry about it. And also you don't have to use quickstart()
on production. Follow here for using Cherrypy with uwsgi
module for production purposes. It is much faster and lighter.