Discussion:
Notify examples
Marcelo Fernandez
2010-08-28 16:31:31 UTC
Permalink
Hello there,

I was trying to make a basic example of notify/listen and I've found a
big difference in the select() call between the examples directory [1]
and the official docs version [2].

The first one say:

select.select([curs],[],[],5)==([],[],[]):

but the docs say:

select.select([conn],[],[],5) == ([],[],[]):

Notice the difference in waiting input from cursor and from the
connection objects; which one is correct?

I'm using psycopg2 *v2.0* in Ubuntu 10.04, and if I try the docs
version (select([conn]...) it doesn't work:

***@marcelo-laptop:~/desarrollo/pg_notify_example$ python notify_docs.py

Waiting for 'NOTIFY test'
Traceback (most recent call last):
File "notify_docs.py", line 13, in <module>
if select.select([conn],[],[],5) == ([],[],[]):
TypeError: argument must be an int, or have a fileno() method.

At first I tought there was a change in the psycopg2 *v2.2* version
(which will be available in Ubuntu 10.10), but the trunk/examples
version [1] (select([curs]...) does work perfectly.

Is it a mistake in the documentation? Or there was a change in *v2.2*?

[1] http://initd.org/svn/psycopg/psycopg2/trunk/examples/notify.py
[2] http://initd.org/psycopg/docs/advanced.html#asynchronous-notifications

Regards
--
Marcelo F. Fernández
Buenos Aires, Argentina
Licenciado en Sistemas - CCNA

E-Mail: marcelo.fidel.fernandez-***@public.gmane.org
Blog: http://blog.marcelofernandez.info
Twitter: http://twitter.com/fidelfernandez
Daniele Varrazzo
2010-08-29 20:35:49 UTC
Permalink
On Sat, Aug 28, 2010 at 5:31 PM, Marcelo Fernandez
Post by Marcelo Fernandez
Hello there,
I was trying to make a basic example of notify/listen and I've found a
big difference in the select() call between the examples directory [1]
and the official docs version [2].
[...]
Post by Marcelo Fernandez
Is it a mistake in the documentation? Or there was a change in *v2.2*?
There was a change in 2.2: in this version there has been a general
overhaul of the asynchronous methods and the fileno was moved from the
cursor to the connection, so it's the now connection to be put in the
select list.

Also, the svn trunk you refer to is out of date. Please check the
psycopg homepage for the url of the current repository, that has been
moved to git.

-- Daniele

Loading...