How to get the reactor from ApplicationRunner in autobahnPython(如何从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=True
,ApplicationRunner
就会这样做),只需在代码中需要它的位置from twisted.internet import reactor
执行from twisted.internet import reactor
。
Ayncio已正确封装事件循环(单个进程中可以有多个事件循环)。
txaio提供了一个在两者上都适用的方便方法(它将在Twisted中公开单个全局反应器,并将公开启动ApplicationRunner的事件循环):
txaio.config.loop = reactor
这篇关于如何从AutobahnPython中的ApplicationRunner获取反应堆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从AutobahnPython中的ApplicationRunner获取反应堆


- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01