Re: LISTEN/NOTIFY and python

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "John D(dot) Burger" <john(at)mitre(dot)org>
Cc: "pgsql-general postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: LISTEN/NOTIFY and python
Date: 2007-03-20 15:47:01
Message-ID: 14328.1174405621@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"John D. Burger" <john(at)mitre(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-03-20 15:47:54 Re: shell script to SQL statement: `pg_dump | psql -U`
Previous Message Rick Schumeyer 2007-03-20 15:27:35 pg installation for dummies