Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 强制CherryPy子线程_Python_Multithreading_Cherrypy - Fatal编程技术网

Python 强制CherryPy子线程

Python 强制CherryPy子线程,python,multithreading,cherrypy,Python,Multithreading,Cherrypy,嗯,我希望cherrypy在自动重新加载时杀死所有子线程,而不是“等待子线程终止”,因为我的程序有自己的线程,我不知道如何克服这个问题。CherryPy一直挂在这一行上,我不知道如何让“子线程”终止 ` ` 它永远不会继续。。所以我想强制子线程关闭 我知道这是因为我的应用程序使用自己的线程,我猜cherrypy希望这些线程和cherrypy的一起退出。。。。我能克服这个问题吗 您需要编写停止线程的代码,并将其注册为“停止”事件的侦听器: from cherrypy.process import

嗯,我希望cherrypy在自动重新加载时杀死所有子线程,而不是“等待子线程终止”,因为我的程序有自己的线程,我不知道如何克服这个问题。CherryPy一直挂在这一行上,我不知道如何让“子线程”终止

`

`

它永远不会继续。。所以我想强制子线程关闭


我知道这是因为我的应用程序使用自己的线程,我猜cherrypy希望这些线程和cherrypy的一起退出。。。。我能克服这个问题吗

您需要编写停止线程的代码,并将其注册为“停止”事件的侦听器:

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()

有关更多详细信息,请参阅和。

这适用于quickstart

def stopit():
    print 'stop handler invoked'
    #...
stopit.priority = 10
cherrypy.engine.subscribe('stop', stopit)
为了支持其生命周期,CherryPy定义了一组通用的 将发布到各州的频道:

“启动”:当总线处于“启动”状态时

“主”:周期性地从CherryPy的主循环开始

“停车”:当公共汽车处于“停车”状态时

“优雅”:当总线请求重新加载订户时

“退出”:当总线处于“退出”状态时

此频道将由引擎自动发布到。 因此,请注册任何需要对 发动机的过渡变化

为了使用总线,实现提供了 以下是简单的API:

cherrypy.engine.publish(通道,*args):

channel参数是一个字符串,用于标识接收到的通道 消息应发送到

*args是消息,可以包含任何有效的Python值或对象

cherrypy.engine.subscribe(频道,可调用)

channel参数是标识可调用通道的字符串 将注册到

callable是签名必须匹配的Python函数或方法 将要发表的内容


我开始觉得我应该让CherryPy的自动重新加载过载来杀死我自己的客户。线程。。。但我不知道怎么做。我会调查的。我正在使用快速启动方法。我可以将这些start和stop方法放在我与cherrypy.quickstart()一起使用的根类中吗?或者你能告诉我如何使用这个类MyFeature(),我已经使用了根类root()。。对不起,我没有广泛使用CherryPy..当然;你可以把代码放在任何你喜欢的地方;唯一重要的是在运行quickstart之前订阅它。为什么投票否决了它?这也是cherrypi docs推荐的。但找不到有关优先级字段的信息。
def stopit():
    print 'stop handler invoked'
    #...
stopit.priority = 10
cherrypy.engine.subscribe('stop', stopit)