Re: NOTIFY in asynchronous mode

From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: Tobias Oberstein <tobias(dot)oberstein(at)tavendo(dot)de>, "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: NOTIFY in asynchronous mode
Date: 2011-11-06 20:54:42
Message-ID: 4EB6F412.8030907@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 06/11/11 11:42, Daniele Varrazzo wrote:
> On Nov 5, 2011 12:21 AM, "Jan Urbański" <wulczer(at)wulczer(dot)org> wrote:
>>
>> On 05/11/11 01:15, Daniele Varrazzo wrote:
>
>>> Is it possible to use a naked psycopg connection instead of tx? I
>>> mean, not for the regular query-return cycle, but just for sitting
>>> idle in the reactor and get a callback called upon notify.
>>
>> Not in an easy way, I'm afraid. Stuff put in the reactor as readers need
>> to implement the IReadDescriptor interface[0] which means you'd have to
>> wrap the connection object with something that proxies fileno() to the
>> connection and looks for notifies when doRead() is called on it.
>
> Doh, sorry if I made it too easy. It would be great if notifies could
> be used easily from Twisted: they seem made for each other like bread
> and nutella. Please keep us informed if you manage to add the support
> to the library.

No problem ;) I think it was just what I needed to add support for
NOTIFY to txpostgres, which is now present in HEAD.

Turns out it required learning more that I cared to know about epoll and
fixing some unrelated bugs, but it's done.

> Comparatively, receiving notifies in greenlet environments is
> straightforward:
> <http://initd.org/psycopg/articles/2010/12/01/postgresql-notifications-psycopg2-eventlet/>.

Cool, I tried implementing that with Twisted and ended up with the
following:

https://gist.github.com/1343455

Requires txpostgres HEAD and txWebSocket, preferably from my fork
(https://github.com/wulczer/txWebSocket) to have it support newer
versions of the WebSocket protocol, as found in recent Chrome and Firefox.

All in all, thank you everyone for your input and sorry for conducting a
discussion that would belong more on the Twisted mailing list than here :)

Cheers,
Jan

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Tobias Oberstein 2011-11-09 18:53:32 Re: NOTIFY in asynchronous mode
Previous Message Daniele Varrazzo 2011-11-06 10:42:34 Re: NOTIFY in asynchronous mode