如何从处理程序中退出异步调度程序?

如何从处理程序中退出异步调度程序?,第1张

如何从处理程序退出异步调度程序?

在查看源代码后很快就可以解决。感谢文档直接链接到源!

有一个ExitNow例外,你可以简单地从应用程序,它退出循环提高。

使用

EchoHandler
文档中的示例,我将其修改为在接收数据时立即退出。

class EchoHandler(asyncore.dispatcher_with_send):    def handle_read(self):        data = self.recv(8192)        if data: raise asyncore.ExitNow('Server is quitting!')

另外,请记住,您可以抓住它,

ExitNow
因此如果在内部使用它,则应用程序不会启动。这是我的一些资料:

    def run(config):        instance = LockServer(config)        try: asyncore.loop()        except asyncore.ExitNow, e: print e


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5667251.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存