【问题标题】:How to get the reactor from ApplicationRunner in autobahnPython如何在 autobahnPython 中从 ApplicationRunner 获取反应器
【发布时间】:2016-09-30 13:31:07
【问题描述】:

我有一个高速公路客户端,它使用高速公路上的 ApplicationRunner 类连接到 WAMP 路由器(交叉开关)。在主要部分中,它附加了我的 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(...)。 我怎样才能访问这个反应堆。我在文档中没有找到任何内容。

【问题讨论】:

    标签: python twisted autobahn crossbar


    【解决方案1】:

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

    asyncio 已经正确封装了事件循环(一个进程中可以有多个事件循环)。

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

    【讨论】:

      猜你喜欢
      • 2020-07-11
      • 2021-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 2017-03-23
      • 2018-06-13
      • 2020-06-11
      相关资源
      最近更新 更多