嗯,我希望cherrypy在自动重新加载时杀死所有子线程,而不是“等待子线程终止”,因为我的程序有自己的线程,而我不知道如何克服这一点。CherryPy一直挂在这一行上,我不知道该怎么做才能让“子线程”终止……
`
[05/Jan/2010:01:14:24] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 8080)) shut down
[05/Jan/2010:01:14:24] ENGINE Stopped thread '_TimeoutMonitor'.
[05/Jan/2010:01:14:24] ENGINE Bus STOPPED
[05/Jan/2010:01:14:24] ENGINE Bus EXITING
[05/Jan/2010:01:14:24] ENGINE Bus EXITED
[05/Jan/2010:01:14:05] ENGINE Waiting for child threads to terminate...`
它永远不会继续..所以我想强制子线程关闭...
我知道这是因为我的应用程序正在使用自己的线程,我猜cherrypy希望这些线程与CherryPy的线程一起退出……我能克服这个吗?
发布于 2010-01-06 00:48:51
您需要编写停止线程的代码,并将其注册为“stop”事件的侦听器:
from cherrypy.process import plugins
class MyFeature(plugins.SimplePlugin):
"""A feature that does something."""
def start(self):
self.bus.log("Starting my feature")
self.threads = mylib.start_new_threads()
def stop(self):
self.bus.log("Stopping my feature.")
for t in self.threads:
mylib.stop_thread(t)
t.join()
my_feature = MyFeature(cherrypy.engine)
my_feature.subscribe()有关更多详细信息,请参阅http://www.cherrypy.org/wiki/BuiltinPlugins和http://www.cherrypy.org/wiki/CustomPlugins。
发布于 2013-08-09 16:36:02
这适用于快速入门
def stopit():
print 'stop handler invoked'
#...
stopit.priority = 10
cherrypy.engine.subscribe('stop', stopit)为了支持其生命周期,CherryPy定义了一组公共通道,这些通道将在各种状态下发布到:
“start”:当总线处于“start”状态时
“main”:定期从CherryPy的主循环
“停止”:当公交车处于“停止”状态时
“graceful”:当总线请求重新加载订阅者时
“exit”:总线处于“exit”状态时
此通道将由引擎自动发布到。因此,注册任何需要对引擎的转换更改做出反应的订阅者。
。。
为了与总线协同工作,该实现提供了以下简单的
:
Cherrypy.engine.publish(通道,*参数):
channel参数是标识消息应发送到的通道的字符串
*args是消息,可能包含任何有效的Python值或对象。
cherrypy.engine.subscribe(channel,可调用):
channel参数是一个字符串,用于标识可调用对象将注册到的通道。
callable是一个Python函数或方法,其签名必须与将要发布的内容相匹配。
https://stackoverflow.com/questions/2004514
复制相似问题