Skip to content

Feature Request: better support for LISTEN/NOTIFY? #1089

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

Open
racinette opened this issue Oct 11, 2023 · 3 comments
Open

Feature Request: better support for LISTEN/NOTIFY? #1089

racinette opened this issue Oct 11, 2023 · 3 comments

Comments

@racinette
Copy link

Currently, you have to execute a dummy query like SELECT 1 every time you want to get a hold of new notifications from the server. Can anything similar to aiopg be implemented in asyncpg?

https://aiopg.readthedocs.io/en/stable/examples.html#usage-of-listen-notify-commands
https://www.psycopg.org/docs/connection.html#connection.poll

@Victor-N-Suadicani
Copy link

Victor-N-Suadicani commented Apr 24, 2024

Is this still a problem? I just tried this small test and it seems to work fine (prints "Got notification" every second). I don't need to do any dummy queries.

import asyncpg
import asyncio

async def notify(conn):
    count = 0
    while True:
        await asyncio.sleep(1)
        await conn.execute(f"notify foo, '{count}'")
        count += 1

async def notified(conn, pid, channel, payload):
    print(f"Got notification on {channel}: {payload}")

async def main():
    conn = await asyncpg.connect("postgresql://postgres:postgres@localhost")
    await conn.add_listener("foo", notified)
    await notify(conn)

asyncio.run(main())

@racinette
Copy link
Author

@Victor-N-Suadicani but you are notifying the same connection on which you're listening. Meaning, probably your conn.execute becomes the dummy query.

@Victor-N-Suadicani
Copy link

Possibly I guess. You can try with two different connections and see if it still works I suppose. Sorry, I have no interest in this issue any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants