Closed remy-sl closed 4 years ago
There's an AIOConnectionPool
for using asyncio connections:
from bonsai.asyncio import AIOConnectionPool
async with pool.spawn() as conn:
res = await conn.whoami()
print(res)
It's listed in the API docs, but documentation lacks of examples about using it. Every method of AIOConnectionPool
is awaitable. The spawn method uses a custom async context manger wrapper, because asynccontextmanager
is a new feature that's only available from 3.7.
Oh snap.. I suddenly feel very stupid that I missed it. Anyway, thanks a lot!
Hello noirello,
I have tried to find the documentation referring to AIConnectionPool and I can't seem to find it. Would you be willing to point me towards documentation or give me a more in-depth example of this new functionality?
I am trying to create an AI Connection pool that will create new connections with different credentials each time.
Thank you, The Cheese Dev
Here's in the docs and it's inherited from ConnectionPool, where you can find the implemented methods. But it's designed to use the same credentials for every connection.
Ah gotcha, do you have any advice for my desired functionality within your library?
I think connection pools do not work well with async. I may be doing something wrong of course. Here goes nothing:
This results in
What also makes me think that the async implementation was not designed to work with connection pools is the fact that
pool.spawn
does not work at all because it is wrapped incontextlib.contextmanager
and obviously lacks__aenter__
and__aexit__
methods so it fails when used withasync with
.Any advice on how to bite this? I am designing an application for quite high throughput.
EDIT:
Okay, I think I have hacked my way around it like this
This works fine, but now I get this ugly warning
not sure what to do with this and what the side effects are.