如何从autobahnPython中的ApplicationRunner获取反应器

时间:2016-09-30 13:31:08

标签: python twisted autobahn crossbar

我有一个高速公路客户端,使用autobahn的ApplicationRunner类连接到WAMP路由器(crossbar)。在主要部分中,它附加了我的ApplicationSession类" REScheduler"像这样:

class Chromosome{
    double gene1;  // 0.0 < gene1 < 100.0
    double gene2;  // -7.3 < gene2 < 9.0
}

现在我需要应用程序运行器启动的反应器用于其他目的。像例如拨打一些class Chromosome{ int gene1; // 200 < gene1 < 1000 double gene2; // 50.0 < gene2 double gene3; // gene3 < -5.0 } 。 我怎样才能进入这个反应堆。我在文档中找不到任何内容。

1 个答案:

答案 0 :(得分:2)

Twisted(遗憾地)使用(进程)全局reactor对象。这意味着,一旦选择了反应堆(ApplicationRunner如果设置了start_reactor=True),只需在您代码中的位置执行from twisted.internet import reactor

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

  

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