【问题标题】:Using cassandra python driver with twisted使用带扭曲的 cassandra python 驱动程序
【发布时间】:2017-11-22 12:35:01
【问题描述】:

我的 python 应用程序使用了 twisted,并且在后台使用了 cassandra python 驱动程序。 Cassandra python驱动可以使用cassandra.io.twistedreactor.TwistedConnection作为连接类来使用twisted作为查询方式。

TwistedConnection 类使用计时器和reactor.callLater 来检查查询任务是否超时。

问题是当我使用 cassandra ORM (cassandra.cqlengine.models.Model) 进行查询时。

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model


# ORM for user settings
class UserSettings(Model):
    userid = columns.Text(primary_key=True)
    settings = columns.Text()

# Function registered with autobahn/wamp
def worker():
    userid = "96c5d462-cf7c-11e7-b567-b8e8563d0920"

    def _query():
        # This is a blocking call, internally calling twisted reactor
        # to collect the query result
        setting = model.UserSettings.objects(userid=userid).get()
        return json.loads(setting.settings)

    threads.deferToThread(_query)

twisted.trial 单元测试中运行时。使用上述代码的测试总是以

失败

失败:twisted.trial.util.DirtyReactorAggregateError: Reactor was 不干净。

DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
<DelayedCall 0x10e0a2dd8 [9.98250699043274s] called=0 cancelled=0 TwistedLoop._on_loop_timer()

在使用此代码的高速公路工作人员中,但工作正常。

TwistedConnection 的 cassandra 驱动程序代码一直在调用 callLater,但我无法找到方法来查找这些调用中是否仍有待处理的调用,因为这些调用隐藏在 TwistedLoop 类中。

问题:

  • 这是处理 cassandra 查询的正确方法吗(这又称为扭曲反应器)
  • 如果是,有没有办法解决由于 cassandra 驱动程序超时 (reactor.callLater) 而导致的 DelayedCall

【问题讨论】:

    标签: python-3.x twisted cassandra-3.0 autobahn cassandra-driver


    【解决方案1】:

    只是我的理解:

    1. 也许您需要在过滤时调用.filter 函数?如docssetting = model.UserSettings.objects.filter(userid=userid).get()中所述

    2. 也许可以通过更改 Cassandra conf yaml 文件中的响应时间来解决?

    【讨论】:

      猜你喜欢
      • 2017-08-07
      • 2015-04-12
      • 2017-11-26
      • 2018-06-15
      • 2018-11-10
      • 2013-08-30
      • 2017-11-05
      • 2018-01-05
      • 2018-04-21
      相关资源
      最近更新 更多