1

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.

vgmoose
  • 445
  • 4
  • 10

2 Answers2

2

One thing CherryPy is doing in background is checking for changes in files and imported modules and then re-execute the process. Switching the autoreloader off with cherrypy.config.update({'engine.autoreload.on' : False}) uses less CPU. CPU usage dropped from 1.5% to less than 0.3% for me.

amotzek
  • 41
  • 1
  • 6
1

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.

Amin Etesamian
  • 3,363
  • 5
  • 27
  • 50