-
-
Notifications
You must be signed in to change notification settings - Fork 220
Closed
Milestone
Description
I have a use case where a single AsyncConnection needs to listen on different channels. Which to listen on becomes known in runtime, e.g. connected clients determine what is listened and unlistened on. Unfortunately, when using the AsynConnection.notifies() generator, further AsyncConnection.execute() calls will hang.
async def test_notifies():
con = await psycopg.AsyncConnection.connect(PSYCOPG_DSN, autocommit=True)
await con.set_autocommit(True)
async def notifier():
i = 0
while True:
await con.execute(f'notify foo, \'{i}\'')
print(f"notified {i}")
await asyncio.sleep(1)
i += 1
if i==10:
break
await con.close()
async def receiver():
print("receiver: LISTENING ")
cur = con.cursor()
await cur.execute("listen foo")
gen = con.notifies()
async for n in gen:
print("receiver: notified ")
print(n)
workers = [notifier(), receiver()]
await asyncio.gather(*workers)
asyncio.run(test_notifies())
Output of the program:
receiver: LISTENING
notified 0
After that the program hangs.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels