logo       

Re: notify.py: msg#00078

python.db.psycopg.devel

Subject: Re: notify.py

Il giorno ven, 17/03/2006 alle 13.07 -0600, Michael Hipp ha scritto:
> I'm trying to refactor some of my code to use the "new" method of doing
> a LISTEN on the database, I'm stuck on this key piece of code:
>
> print "Waiting for 'NOTIFY test'"
> while 1:
> if select.select([curs],[],[],5)==([],[],[]):
> print "Timeout"
> else:
> if curs.isready():
> print "Got NOTIFY: %s" % str(curs.connection.notifies.pop())
>
>
> I understand the 'select' part.
>
> What does curs.isready() do? What happens if it comes back as not True?

It just means that the current data transfer from the backend is still
in progress. But given the fact that only the Really Brave (TM) would
use psycopg async calls right now it will never happen to you (but you
must still call .isready() because it will gather the pending notifies.)

> Also, I presume the '.pop()' ought to be called repeatedly until there
> are no more? How does one know that?

curs.connection.notifies is a plain list. You can len() it and use any
other list method.

> Does this all replace the previous way of doing things that looked
> something like this?
>
> n = curs.notifies()[0][0] # Get the notification

Yes, because the notifies are a connection property so all cursors
derived from the same connection get the same set of notifies using
the .connection.notifies attribute.

Hope this helps,
federico


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise