Re: LISTEN/NOTIFY and python - Mailing list pgsql-general

From Tom Lane
Subject Re: LISTEN/NOTIFY and python
Date
Msg-id 14328.1174405621@sss.pgh.pa.us
Whole thread Raw
In response to LISTEN/NOTIFY and python  ("John D. Burger" <john@mitre.org>)
Responses Re: LISTEN/NOTIFY and python  ("John D. Burger" <john@mitre.org>)
List pgsql-general
"John D. Burger" <john@mitre.org> writes:
> Does anyone have any suggestions for how to write client python code
> that uses LISTEN?  The only thing I can find is the older PyGreSQL
> module (import pg), which has getnotify(), but this seems to require
> busy-waiting.  Is there any way to do this that will use select() or
> something under the covers, so my client doesn't spin up the cpu?
> (Yes, I know I could poll-sleep-poll-sleep - that's what I'll do if
> there's nothing cleaner.)

The standard approach when using libpq directly is to get the file
descriptor number of the backend connection with PQsocket(), then
include that in the set of FDs that the client app's idle loop
select()s or poll()s on.  Read-ready on the socket doesn't necessarily
mean that a NOTIFY has arrived, but it's at least sufficient info
to justify waking up and checking libpq's status.

Dunno if you can translate that into python readily ...

            regards, tom lane

pgsql-general by date:

Previous
From: Rick Schumeyer
Date:
Subject: pg installation for dummies
Next
From: Tom Lane
Date:
Subject: Re: shell script to SQL statement: `pg_dump | psql -U`