Re: [cx-oracle-users] subscribe in cx_oracle
Brought to you by:
atuining
From: Anthony T. <ant...@gm...> - 2010-11-12 05:15:09
|
Hi, This is actually just a simple problem and you'll probably kick yourself when you realize what is going on. :-) In your method you are creating the subscription and then, as soon as the function ends, the subscription goes out of scope and is immediately destroyed! If you return the subscription from the method or you make sub a global by adding "global sub" just before creating the subscription all works as expected. Anthony On Wed, Nov 10, 2010 at 5:45 PM, Mark Bell <mar...@bl...> wrote: > I'm testing the subscribe() for change notification, but I'm having some > problems. If I copy the example really closely I get notifications ok, but if I > try to put the call to conn.subscribe(...) into a function then it doesn't work, > I don't get any errors but changes are not reported. > > e.g. if I have: > > --------------- > conn = cx_Oracle.connect(user, pass, db, events = True) > sql = "select * from <some_table>" > > def OnChanges(message): > print "Message received" > > sub = conn.subscribe(callback = OnChanges > ,operations = cx_Oracle.OPCODE_UPDATE > ,rowids = False) > sub.registerquery(sql) > sleep(60) > --------------- > it works fine. > > But if I do this: > > --------------- > conn = cx_Oracle.connect(user, pass, db, events = True) > sql = "select * from <some_table>" > > def OnChanges(message): > print "Message received" > > def subscribe(): > sub = conn.subscribe(callback = OnChanges > ,operations = cx_Oracle.OPCODE_UPDATE > ,rowids = False) > sub.registerquery(sql) > > subscribe() > sleep(60) > --------------- > it doesn't give any errors, but doesn't report any changes. Am I doing something > wrong? > > mark. > > > > ------------------------------------------------------------------------------ > Centralized Desktop Delivery: Dell and VMware Reference Architecture > Simplifying enterprise desktop deployment and management using > Dell EqualLogic storage and VMware View: A highly scalable, end-to-end > client virtualization framework. Read more! > http://p.sf.net/sfu/dell-eql-dev2dev > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |