0

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?

ataylor
  • 64,891
  • 24
  • 161
  • 189
user89021
  • 14,784
  • 16
  • 53
  • 65

1 Answers1

5
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.

user89021
  • 14,784
  • 16
  • 53
  • 65