Re: LISTEN/NOTIFY and python

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: LISTEN/NOTIFY and python
Дата
Msg-id 14328.1174405621@sss.pgh.pa.us
обсуждение исходный текст
Ответ на LISTEN/NOTIFY and python  ("John D. Burger" <john@mitre.org>)
Ответы Re: LISTEN/NOTIFY and python  ("John D. Burger" <john@mitre.org>)
Список 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 по дате отправления:

Предыдущее
От: Rick Schumeyer
Дата:
Сообщение: pg installation for dummies
Следующее
От: Tom Lane
Дата:
Сообщение: Re: shell script to SQL statement: `pg_dump | psql -U`