postgresql notifications
Witek
w_w at gazeta.pl
Wed May 28 04:40:35 EDT 2003
Witek wrote:
> Gerhard Häring wrote:
>
>>> I'm using pypgsql to connect to postgresql database (7.2, 7.3).
>>> I recieve PgNotify object using notifies() method of connection
>>> object, but it's fields values are random chars and wrong process id.
>>> Is there someone, who put it to work?
>> The pyPgSQL source distribution includes examples for notifications
>> (examples/demo2a.py, examples/demo2b.py).
>> Please report back if you still have problems.
> They are not working under Linux or Windows. I tried examples from
> gnumed project as well.
My code:
#!/usr/bin/python
import sys
import select
from pyPgSQL import libpq
cnx = libpq.PQconnectdb('dbname=### user=### password=### host=###')
res = cnx.query('LISTEN "test"')
while 1:
ready_sockets = select.select([cnx.socket], [], [], 1.0)[0]
if len(ready_sockets) > 0:
cnx.consumeInput()
n = cnx.notifies()
while n:
print dir(n)
print n.be_pid
print n.relname
n = cnx.notifies()
Output:
['be_pid', 'relname']
21541
%T
['be_pid', 'relname']
21541
p%T
['be_pid', 'relname']
21541
%T
be_pid value is ok. But i cannot decode relname value in any way.
witek
More information about the Python-list
mailing list