Re: NOTIFY in asynchronous mode - Mailing list psycopg

From Jan Urbański
Subject Re: NOTIFY in asynchronous mode
Date
Msg-id 4EB4818E.6020205@wulczer.org
Whole thread Raw
In response to NOTIFY in asynchronous mode  (Tobias Oberstein <tobias.oberstein@tavendo.de>)
Responses Re: NOTIFY in asynchronous mode
List psycopg
On 05/11/11 01:15, Daniele Varrazzo wrote:
> On Sat, Nov 5, 2011 at 12:03 AM, Jan Urbański <wulczer@wulczer.org> wrote:
>> On 04/11/11 21:23, Daniele Varrazzo wrote:
>>> On Fri, Nov 4, 2011 at 7:12 PM, Tobias Oberstein
>>> <tobias.oberstein@tavendo.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

psycopg by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Re: NOTIFY in asynchronous mode
Next
From: Daniele Varrazzo
Date:
Subject: Re: NOTIFY in asynchronous mode