public inbox for [email protected]
help / color / mirror / Atom feedFrom: Daniele Varrazzo <[email protected]>
To: Psycopg <[email protected]>
Subject: Improving `Connection.notifies()` in Psycopg 3.2
Date: Wed, 25 Oct 2023 00:16:50 +0200
Message-ID: <CA+mi_8Z6pSgVOpWgretCKpop8MzEWnJ-R-A3c6KQdodYY4D0YQ@mail.gmail.com> (raw)
Hello,
Psycopg 3 introduced a `Connection.notifies()` generator, yielding
async notifications as they are received:
for n in conn.notifies():
do_something_with(n)
However it proved harder to use than expected:
- during the loop, the connection cannot be used to run queries (and
some would be pretty useful, such as LISTEN/UNLISTEN to change
the channels to listen at);
- it is not clear how to stop the generator. If assigned to a variable
`gen`, it can be closed with `gen.close()` but it must be done from an
external task/thread if the generator is waiting and I seem to
remember that it's not possible to call close on an async generator
from an external task.
In https://github.com/psycopg/psycopg/pull/673 I propose to add
optional parameters to the function:
- `timeout`: max time to wait for notifications;
- `stop_after`: stop after receiving this number of notifications (may
return more than what requested if received in the same batch);
I think these additions should make the generator easier to use, but
I'm not completely sold on its interface.
What do you think? Comments are welcome.
Cheers
-- Daniele
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Improving `Connection.notifies()` in Psycopg 3.2
In-Reply-To: <CA+mi_8Z6pSgVOpWgretCKpop8MzEWnJ-R-A3c6KQdodYY4D0YQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox