4

I created the following function to shutdown cherrypy:

import cherrypy
cherrypy.engine.exit()

Name of the file: shutdown.py. And then I enter the command python shutdown.py in the command line. The following messages showed up:

[06/Sep/2014:11:28:22] ENGINE Bus STOPPING
[06/Sep/2014:11:28:22] ENGINE HTTP Server None already shut down
[06/Sep/2014:11:28:22] ENGINE No thread running for None.
[06/Sep/2014:11:28:22] ENGINE No thread running for None.
[06/Sep/2014:11:28:22] ENGINE Bus STOPPED
[06/Sep/2014:11:28:22] ENGINE Bus EXITING
[06/Sep/2014:11:28:22] ENGINE Bus EXITED

However, CherryPy is still running. How do I shutdown CherryPy then?

Also, what if I have multiple cherrypy servers running at the same time? Does the shutdown.py kill all of them?

Randy Tang
  • 4,283
  • 12
  • 54
  • 112

2 Answers2

3

CherryPy application is contained in ordinary Python process. To treat CherryPy application like a server (e.g. mysql, nginx, etc. which you can /etc/init.d/mysql stop) you should deploy it accordingly.

For an ad-hoc case, just tell cherryd to save pid file with --pidfile or integrate PIDFile plugin into your code directly. Then just kill `cat /path/to/pidfile`.

For a full-blown deployment read this answer.

Community
  • 1
  • 1
saaj
  • 23,253
  • 3
  • 104
  • 105
  • Thanks, but I used the `server.py` to start cherrypy as provided by this tutorial (https://www.digitalocean.com/community/tutorials/how-to-deploy-python-wsgi-applications-using-a-cherrypy-web-server-behind-nginx). How can obtain the process id of cherrypy? – Randy Tang Sep 08 '14 at 13:13
  • I've already told you -- use PIDFile plugin. Something like ``plugins.PIDFile(engine, '/run/yourapp/yourapp.pid').subscribe()``. Take a look at [cherryd source](https://bitbucket.org/cherrypy/cherrypy/src/2a045705a5e403699aab915ab32ea8484f259fa1/cherrypy/cherryd?at=default#cl-39) for the context. – saaj Sep 08 '14 at 15:06
0

This question is 6 years ago, but I want to answer something important. The best way to shutdown Cherrypy server is setting the following configuration in your code:

cherrypy.config.update({ 'server.shutdown_timeout': 1 })

Of this way you are sure the server is shutdown, you can see more about that in this issue. So, I hope this can help someone.

Carmoreno
  • 1,271
  • 17
  • 29