Skip to content

Instantly share code, notes, and snippets.

@vskrachkov
Created December 30, 2019 17:30
Show Gist options
  • Save vskrachkov/4f90be1bf0becee2009856366512e5de to your computer and use it in GitHub Desktop.
Save vskrachkov/4f90be1bf0becee2009856366512e5de to your computer and use it in GitHub Desktop.
listen notifications from postgresql using asyncpg
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