如何从AutobahnPython中的ApplicationRunner获取反应堆 [英] How to get the reactor from ApplicationRunner in autobahnPython

查看:25
本文介绍了如何从AutobahnPython中的ApplicationRunner获取反应堆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Autobahn客户端,它使用Autobahn中的ApplicationRunner类连接到WAMP路由器(Crosbar)。在主要部分中,它按如下方式附加了我的ApplicationSession类"Rescheduler":

if __name__ == '__main__':
    from autobahn.twisted.wamp import ApplicationRunner

    runner = ApplicationRunner(url=u"ws://localhost:8080/ws", realm=u"RE_acct")

    runner.run(REScheduler, start_reactor=True, auto_reconnect=True)

现在,我还需要应用程序运行器启动的反应器用于其他目的。例如,调用一些reactor.callLater(...)。 我怎么才能进入这个反应堆。我在文档中没有找到任何内容。

推荐答案

Twisted(遗憾的是)使用(进程)全局反应器对象。这意味着,一旦选择了反应器(如果设置start_reactor=TrueApplicationRunner就会这样做),只需在代码中需要它的位置from twisted.internet import reactor执行from twisted.internet import reactor

Ayncio已正确封装事件循环(单个进程中可以有多个事件循环)。

txaio提供了一个在两者上都适用的方便方法(它将在Twisted中公开单个全局反应器,并将公开启动ApplicationRunner的事件循环):txaio.config.loop = reactor

这篇关于如何从AutobahnPython中的ApplicationRunner获取反应堆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆