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获取反应堆


基础教程推荐
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01