duneanalytics / dune-client

A framework for interacting with Dune Analytics' officially supported API service
Apache License 2.0
85 stars 22 forks source link

How To Use Async Client? #38

Closed bh2smith closed 1 year ago

bh2smith commented 1 year ago

cc @eliseygusev

I am trying to use this async client and keep running into these errors


RuntimeError: Timeout context manager should be used inside a task
2022-11-16 00:49:21,368 ERROR asyncio Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x106ba64a0>

I have tried putting a close session after the refresh call, like so

response = await self.dune.refresh(query, ping_frequency=10)
await self.dune.close_session()

but still get them. Would love if you could show me how to use this from an external package and maybe make it somehow more convenient for external users.

I have written some elementary "async" wrapper code on the regular DuneClient like:

async def fetch(self, query: Query) -> list[DuneRecord]:
    response = await asyncio.to_thread(
        self.dune.refresh, query, ping_frequency=10
    )

(which could probably be pushed deeper into the _post and _get methods), but it works just fine without all this "close_session" stuff. Is there something wrong with this simplified approach?

Originally posted by @bh2smith in https://github.com/cowprotocol/dune-client/issues/31#issuecomment-1316045313

bh2smith commented 1 year ago

Closed by #39