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-05 00:21:34
Message-ID: 4EB4818E.6020205@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 05/11/11 01:15, Daniele Varrazzo wrote:
> On Sat, Nov 5, 2011 at 12:03 AM, Jan Urbański <wulczer(at)wulczer(dot)org> wrote:
>> On 04/11/11 21:23, Daniele Varrazzo wrote:
>>> On Fri, Nov 4, 2011 at 7:12 PM, Tobias Oberstein
>>> <tobias(dot)oberstein(at)tavendo(dot)de> wrote:
>>>
>>>> is it possible to use notification (sent via NOTIFY from Postgres) in asynchronous mode?
>>>
>>> Yes: you should register the connection's file descriptor in the
>>> twisted reactor so that you can be notified by the kernel when the
>>> server sends you a notification.
>>
>> Actually... it won't work out of the box. I got a patch from someone
>> that added NOTIFY support for txpostgres, but it broke some unit tests
>> and there were a few other minor issues with it and then I kind of
>> forgot about it.
>
> 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.

Since you have to connect first, and issue the LISTEN statement, you
have to go through the entire polling cycle, at which point you
basically would have implemented half of txpostgres :)

J

[0]
http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IReadDescriptor.html

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Tobias Oberstein 2011-11-05 10:30:23 Re: NOTIFY in asynchronous mode
Previous Message Daniele Varrazzo 2011-11-05 00:15:30 Re: NOTIFY in asynchronous mode