PyQT Quamash循环和open_connection'ValueError:循环参数必须与Future'一致'

时间:2018-01-19 13:13:11

标签: asynchronous pyqt5 rethinkdb python-asyncio

我在pyqt上使用quamash循环(async)和其他模块连接到带有异步的RethinkDB。如果我不使用quamash,RethinkDb模块将以完美的方式连接。但是当使用quamash循环时尽管把它放在每个关键的参数循环上它都会失败:

  File "/home/dpineda/.virtualenvs/dragoncharts/lib/python3.6/site-packages/rethinkdb/asyncio_net/net_asyncio.py", line 148, in connect
    loop=self._io_loop)
  File "/usr/local/lib/python3.6/asyncio/streams.py", line 76, in open_connection
    lambda: protocol, host, port, **kwds)
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 731, in create_connection
    yield from tasks.wait(fs, loop=self)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 311, in wait
    fs = {ensure_future(f, loop=loop) for f in set(fs)}
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 311, in <setcomp>
    fs = {ensure_future(f, loop=loop) for f in set(fs)}
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 514, in ensure_future
    raise ValueError('loop argument must agree with Future')
ValueError: loop argument must agree with Future

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/events.py", line 127, in _run
    self._callback(*self._args)
  File "/home/dpineda/Proyectos/TaskTools/tasktools/taskloop.py", line 40, in renew_quamash
    raise task.result()
  File "/home/dpineda/Proyectos/TaskTools/tasktools/taskloop.py", line 11, in coromask
    obtained=await coro(*args)
  File "/home/dpineda/Proyectos/DragonCharts/dragoncharts/qtgui/interface.py", line 382, in updates
    await self.read_stations_queue()
  File "/home/dpineda/Proyectos/DragonCharts/dragoncharts/qtgui/interface.py", line 257, in read_stations_queue
    conn=await self.connect_rethinkdb()
  File "/home/dpineda/Proyectos/DragonCharts/dragoncharts/qtgui/interface.py", line 315, in connect_rethinkdb
    conn=await r.async_connect()
  File "/home/dpineda/Proyectos/NetworkTools/networktools/dbs/rethinkdb.py", line 43, in async_connect
    **kwargs)
  File "/home/dpineda/.virtualenvs/dragoncharts/lib/python3.6/site-packages/rethinkdb/asyncio_net/net_asyncio.py", line 293, in reconnect
    return (yield from self._instance.connect(timeout))
  File "/home/dpineda/.virtualenvs/dragoncharts/lib/python3.6/site-packages/rethinkdb/asyncio_net/net_asyncio.py", line 156, in connect
    (self._parent.host, self._parent.port, str(err)))
rethinkdb.errors.ReqlDriverError: Could not connect to atlas.csn.uchile.cl:28015. Error: loop argument must agree with Future

所以,到目前为止,我的技能已达到控制的极限,因为这是quamash和asyncio库之间的兼容性问题,我认为!

或者,有一些解决方案吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

确保将quamash循环设置为默认的全局循环:

from quamash import QEventLoop

loop = QEventLoop(app)
asyncio.set_event_loop(loop)

它有很高的机会帮助它。

但如果没有,请将代码片段放在脚本顶部以使其在任何异步模块导入之前执行。

<强> UPD:

没有检查它是否有效,但您可以尝试使用dependency injection through multiple inheritance来获取具有两个事件循环属性的类:

import asyncio
from quamash import QEventLoop

AEventLoop = type(asyncio.get_event_loop())


class QEventLoopPlus(QEventLoop, AEventLoop):
    pass


loop = QEventLoopPlus(app)
asyncio.set_event_loop(loop)