user89021
user89021

Reputation: 15172

How to shutdown cherrypy from within?

I am developing on cherrypy, I start it from a python script.

For better development I wonder what is the correct way to stop cherrypy from within the main process (and not from the outside with ctrl-c or SIGTERM).

I assume I have to register a callback function from the main application to be able to stop the cherrypy main process from a worker thread.

But how do I stop the main process from within?

Upvotes: 0

Views: 3974

Answers (1)

user89021
user89021

Reputation: 15172

import sys
class MyCherryPyApplication(object):

  def default(self):
    sys.exit()
  default.exposed = True

cherrypy.quickstart(MyCherryPyApplication())

Putting a sys.exit() in any request handler exits the whole server

I would have expected this only terminates the current thread, but it terminates the whole server. That's what I wanted.

Upvotes: 5

Related Questions