<p>这适用于quickstart</p>
<pre><code>def stopit():
print 'stop handler invoked'
#...
stopit.priority = 10
cherrypy.engine.subscribe('stop', stopit)
</code></pre>
<blockquote>
<p>In order to support its life-cycle, CherryPy defines a set of common
channels that will be published to at various states:</p>
<p>“start”: When the bus is in the “STARTING” state</p>
<p>“main”: Periodically from the CherryPy’s mainloop</p>
<p><strong>“stop”: When the bus is in the “STOPPING” state</strong></p>
<p>“graceful”: When the bus requests a reload of subscribers</p>
<p>“exit”: When the bus is in the “EXITING” state</p>
<p>This channel will be published to by the engine automatically.
Register therefore any subscribers that would need to react to the
transition changes of the engine.</p>
</blockquote>
<p>。。在</p>
<blockquote>
<p>In order to work with the bus, the implementation provides the
following simple API:</p>
<p>cherrypy.engine.publish(channel, *args):</p>
<p>The channel parameter is a string identifying the channel to which the
message should be sent to</p>
<p>*args is the message and may contain any valid Python values or objects.</p>
<p><strong>cherrypy.engine.subscribe(channel, callable)</strong>:</p>
<p>The channel parameter is a string identifying the channel the callable
will be registered to.</p>
<p>callable is a Python function or method which signature must match
what will be published.</p>
</blockquote>