|
Re: notify.py: msg#00078python.db.psycopg.devel
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> |
|---|---|---|
| Previous by Date: | notify.py: 00078, Michael Hipp |
|---|---|
| Next by Date: | Binary Cursors?: 00078, Peter Fein |
| Previous by Thread: | notify.pyi: 00078, Michael Hipp |
| Next by Thread: | Re: notify.py: 00078, Michael Hipp |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |