Created
December 30, 2019 17:30
-
-
Save vskrachkov/4f90be1bf0becee2009856366512e5de to your computer and use it in GitHub Desktop.
listen notifications from postgresql using asyncpg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import asyncpg | |
async def main(): | |
conn: asyncpg.Connection = await asyncpg.connect() | |
def callback(c: asyncpg.Connection, pid: int, ch: str, p: str): | |
print(c, pid, ch, p) | |
await conn.add_listener("chan", callback) | |
await asyncio.sleep(10) | |
print("closing connection") | |
await conn.close() | |
if __name__ == "__main__": | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment