【问题标题】:Autobahn | Python: Subscription no longer triggering handler when SubscriptionOptions are provided高速公路 | Python:提供 SubscriptionOptions 时,订阅不再触发处理程序
【发布时间】:2015-06-19 05:27:39
【问题描述】:

我目前正在用 Python 构建一个加密货币交易平台,并使用 Autobahn 接收市场事件。我在使用订阅选项时遇到问题。

当我只使用 (handler, topic) 参数创建订阅并让处理程序接受单个参数时,一切正常。但是,当我使用 (handler, topic, options) 参数创建订阅并让处理程序接受两个参数时,处理程序不会被调用。在文档中,它声明处理程序在这种情况下应该具有三个参数,args、kwargs 和 details。当我让处理程序接受三个参数时,它也不起作用。我绝望地尝试了 0 到 5 个参数之间的所有内容。

简而言之,当我不使用订阅选项并给处理程序一个参数时,它可以正常工作。当我使用订阅选项时,处理程序不会被触发无论我使用多少参数

我尝试打印出这对,它是一个有效的字符串,我尝试打印出选项,它是一个有效的订阅选项对象。请注意,我使用“无”作为匹配条件。我仍然收到订阅确认,并且没有错误。

任何建议将不胜感激。

代码如下。

def onJoin(self, details):
    print("{} client session ready".format(self.exchange))

    def marketEvent(args, kwargs, details):
        print("marketEvent called")

    # Read in configuration files
    try:
        pairs = [line.strip() for line in open("conf/" + self.exchange + ".conf")]
    except:
        print("Configuration file not found for {}!".format(self.exchange))
        sys.exit(1)

    # Subscribe to each currency pair / topic in the conf file
    for pair in pairs:
        try:
            # provide currency pair name to handler 
            options = SubscribeOptions(details_arg = pair)
            yield from self.subscribe(marketEvent, pair, options)
            print("subscribed to {} on {}".format(pair, self.exchange))
        except Exception as e:
            print("could not subscribe to {} on {}: {}".format(pair, exchange, e))
            sys.exit(1)

【问题讨论】:

    标签: python autobahn wamp-protocol


    【解决方案1】:

    在我朋友的帮助下已修复。 marketEvent 所需的签名如下:

    marketEvent(事件, **详情)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多