Thread: [cx-oracle-users] subscribe in cx_oracle
Brought to you by:
atuining
From: Mark B. <mar...@bl...> - 2010-11-11 00:50:24
|
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. |
From: Mark H. <mh...@pi...> - 2010-11-11 01:40:32
|
On 11/10/10 4:45 PM, Mark Bell wrote: > I'm testing the subscribe() for change notification, but I'm having some > it doesn't give any errors, but doesn't report any changes. Am I doing something > wrong? Are you on 10g RAC? If so, it's busted. The DB should save off the address/port of your client process, but it instead saves off the address of whatever database node you've attached to. I was about to go insane talking to oracle support: "change notification doesn't work on RAC" "we dont support python" "type in the example OCI code from your docs. It won't work on RAC" "what application server are you using?" "none, im typing in the OCI code example." "is this a java app?" "no, OCI is for C" "what application are you running? peoplesoft?" "no, the example OCI code in your docs" "in the java" "no, OCI is for C. PLEASE type in the example and you will see it bust" "can you send me your SQL query?" "no, it's not a query, it's a change notification. look at your docs" [escalation due to sales intervention] "change notification doesn't work on RAC" "we dont support python" "type in the example OCI code from your docs. It won't work on RAC" "what application server are you using?" "none, im typing in the OCI code example. its in the book but i'll send you a copy" [days pass] "it works great on my test system" "are you on RAC?" "no" etc etc etc There's a patch for 10gR2. |
From: Mark <mar...@bl...> - 2010-11-11 13:17:58
|
Mark Harrison <mh@...> writes: > Are you on 10g RAC? If so, it's busted. The DB should save off the address/port > of your client process, but it instead saves off the address of whatever database > node you've attached to. Nah, don't think so. Clients might be, but we're not. It works fine if I make the calls at the outside level, but as soon as I try structuring the code so that I make the calls from inside a function or class it breaks. I thought I'd read something about not being able to use classes but I can't find it now, and even just a function seems to break it. I can probably use it like the examples for now, it just makes the code less neat. > I was about to go insane talking to oracle support: :-) Mark. |
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 > |
From: Mark <mar...@bl...> - 2010-11-15 10:40:06
|
Anthony Tuininga <anthony.tuininga@...> writes: > 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. Yes, of course you were quite right. :-) I thought it was some exotic namespace type of problem/restriction with cx_oracle (I saw the namespace attribute on one of the cx_oracle object definitions) ... and it turned out to be a really simple namespace / scoping issue. Ah well. I'd made a deliberate effort to just get on with my test using whatever seemed to work, but once I saw your reply I fixed it to use a more natural structure - and it looks like it's working nicely now :-) Thanks again, Mark. |