--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cherrypy-users/-/KRXNmnzVDrQJ.
To post to this group, send email to cherryp...@googlegroups.com.
To unsubscribe from this group, send email to cherrypy-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en.
Hi Simon,You might simple want to subscribe your function to the CherryPy engine as follow:cherrypy.engine.subscribe('exit', handle_terminate)That function should not take any arguments though.
- Sylvain
On Mon, May 14, 2012 at 3:45 AM, Simon Haines wrote:
Some of my modules used as CherryPy applications spin up their own threads (via threading.Timer) for background processing. However, I can't find a way to latch cherrypy.engine.signal_handler or cherrypy.engine.console_control_handler to properly clean things up when Ctrl-C is pressed on a Linux/Windows console.My server startup code looks like this (Python 2.7.1, CherryPy 3.1.2):# Register of background jobsjobs = []def handle_terminate(event):for job in jobs:print('Terminating %s' % job.name)job.stop()if hasattr(engine, 'signal_handler'):engine.signal_handler.set_handler('SIGTERM', handle_terminate)engine.signal_handler.subscribe()if hasattr(engine, 'console_control_handler'):# Best guess as there is no documentation for console_control_handlerengine.console_control_handler.set_handler('SIGTERM', handle_terminate)
engine.console_control_handler.subscribe()Obviously I'd like to register a listener for the Ctrl-C signal, have the listener clean up the background jobs, and then chain the default handler. Without this, the server never terminates waiting for other threads to finish. Is this possible?Thanks, Simon.
--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cherrypy-users/-/KRXNmnzVDrQJ.
To post to this group, send email to cherrypy-users@googlegroups.com.
To unsubscribe from this group, send email to cherrypy-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en.