1 # notify.py - example of getting notifies
3 # Copyright (C) 2001-2005 Federico Di Gregorio <fog@debian.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any later
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 ## put in DSN your DSN string
19 ## don't modify anything below tis line (except for experimenting)
28 print "Opening connection using dns:", DSN
29 conn = psycopg2.connect(DSN)
30 print "Encoding for this connection is", conn.encoding
32 conn.set_isolation_level(0)
35 curs.execute("listen test")
37 print "Waiting for 'NOTIFY test'"
39 if select.select([curs],[],[],5)==([],[],[]):
43 print "Got NOTIFY: %s" % str(curs.connection.notifies.pop())