1

I'm using on pyqt the quamash loop (async) and other module to connect to a RethinkDB with async. If i do not use quamash the RethinkDb module connects in perfect way. But when uses the quamash loop despite put that on every key argument loop it fails like that:

  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

So, until now, my skills are on the limit to control that because is a problem of compatibility between quamash and asyncio library, i think!

Or, there are some solution to that?

Thanks!

1 Answers1

1

Make sure you set quamash loop as default global loop:

from quamash import QEventLoop

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

There're high chances it alone will help.

But if not, put snippet above to the top of your script to make it being executed before any async module's import.

Upd:

Didn't check if it works, but you can try to use dependency injection through multiple inheritance to get class that has both event loop attributes:

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)
Mikhail Gerasimov
  • 36,989
  • 16
  • 116
  • 159
  • Yes indeed i did that.The problem is, at the end, that QEventLoop quamash doesn't has implemented yet the create_connection method like the AbstracLoop shows on the asyncio source code. So, i think i have to implement an hinherited class over quamash loop :( – David Pineda Osorio Jan 22 '18 at 15:31
  • @DavidPinedaOsorio I updated answer, may be it'll help. – Mikhail Gerasimov Jan 22 '18 at 16:30
  • Cool! Maybe that works, it look like that. Also i read about signals-slots and that has similar functionality to that i need – David Pineda Osorio Jan 22 '18 at 18:32