You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While under most use cases, people will want to use connection pools to manage their connections, there are times where using bare connections turns out to be more practical. However, while connection pools can be opened and closed via context managers:
File "./test.py", line 120, in fetch_ip_list
async with asyncpg.connect(user="postgres") as con:
AttributeError: __aexit__
I personally like using with blocks to handle the scope of resources like this, so this is a step down for me in terms of ergonomics, not to mention rather surprising given that connections coming from connection pools do work as context managers (even though those are merely returned to the pool instead of closed).
The text was updated successfully, but these errors were encountered:
What's the hold-up on this? Not having looked at the code, my intuition is that this should be exceedingly easy to implement. I might contribute a PR on this, but I'd rather not waste my time. @elprans, would you welcome this feature or are you opposed to it?
While under most use cases, people will want to use connection pools to manage their connections, there are times where using bare connections turns out to be more practical. However, while connection pools can be opened and closed via context managers:
...it appears that bare connections created via
asyncpg.connect
do not support this:I personally like using
with
blocks to handle the scope of resources like this, so this is a step down for me in terms of ergonomics, not to mention rather surprising given that connections coming from connection pools do work as context managers (even though those are merely returned to the pool instead of closed).The text was updated successfully, but these errors were encountered: