-
Notifications
You must be signed in to change notification settings - Fork 419
Connection._cleanup not being called when the connection is dropped #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Well, the code is clearly there: asyncpg/asyncpg/protocol/protocol.pyx Lines 863 to 883 in 851d586
So there are two options: 1) Either asyncio is not calling |
How is (2) possible? amain() runs forever and does not |
Well, your particular example is broken, since the |
Uhh… hm. This code: #!/usr/bin/env python3
import asyncpg
import asyncio
cleanup_ran = False
class MyConnection(asyncpg.Connection):
def _cleanup(self):
global cleanup_ran
cleanup_ran = True
return super()._cleanup()
async def amain():
conn = await asyncpg.connect(connection_class=MyConnection)
while True:
await asyncio.sleep(1)
if conn.is_closed():
print(cleanup_ran)
break
if __name__ == '__main__':
asyncio.run(amain()) prints True after restarting postgres. I see. |
@elprans this code: #!/usr/bin/env python3
import asyncpg
import asyncio
async def amain():
conn = await asyncpg.connect()
cleanup_ran = False
def close_listener(_):
nonlocal cleanup_ran
cleanup_ran = True
conn.add_close_listener(close_listener)
while await asyncio.sleep(1, True):
if conn.is_closed():
print(cleanup_ran)
if __name__ == '__main__':
asyncio.run(amain()) when run against my fork prints False every second after restarting postgres. Any clues as to why? |
Put prints into |
Oh hm… I was using |
This issue is continued from comments on #421 and #283.
Problem steps
Run the following code:
Then restart postgres.
Expected results
"1" is printed.
Actual results
Nothing is printed.
System info
uvloop?: Yes
The text was updated successfully, but these errors were encountered: