Subject | exception canceling events |
---|---|
Author | Hamish Moffatt |
Post date | 2018-02-02T05:28:20Z |
Hi,
I'm trying to run a continuous loop waiting for events to be emitted
from Firebird and acting on them.
However I'm occasionally getting an exception:
Traceback (most recent call last):
File "/srv/blah/report_results.py", line 81, in <module>
loop_on_events(('result_changed',), handler)
File "/srv/blah/servicesapi/sessiondb.py", line 27, in loop_on_events
handler()
File "/srv/blah/venv/lib/python2.7/site-packages/fdb/fbcore.py", line
2031, in __exit__
self.close()
File "/srv/blah/venv/lib/python2.7/site-packages/fdb/fbcore.py", line
2109, in close
block.close()
File "/srv/blah/venv/lib/python2.7/site-packages/fdb/fbcore.py", line
1975, in close
"Error while canceling events:")
fdb.fbcore.DatabaseError: ('Error while canceling events:\n- SQLCODE:
-901\n- invalid events id (handle)', -901, 335545021)
My code is simply:
def loop_on_events(events, handler):
conn = session_db.engine.connect() # using SQLAlchemy,
conn.connection is the raw fdb handle
while True:
with conn.connection.event_conduit(events) as conduit:
actual = conduit.wait(timeout=1)
for e in events:
if actual.get(e, 0) > 0:
current_app.logger.debug('Got event')
handler()
loop_on_events(('result_changed',), handler)
This should just run the handler() (which does other DB operations)
every time the event is triggered.
Is this structure wrong?
thanks
Hamish
I'm trying to run a continuous loop waiting for events to be emitted
from Firebird and acting on them.
However I'm occasionally getting an exception:
Traceback (most recent call last):
File "/srv/blah/report_results.py", line 81, in <module>
loop_on_events(('result_changed',), handler)
File "/srv/blah/servicesapi/sessiondb.py", line 27, in loop_on_events
handler()
File "/srv/blah/venv/lib/python2.7/site-packages/fdb/fbcore.py", line
2031, in __exit__
self.close()
File "/srv/blah/venv/lib/python2.7/site-packages/fdb/fbcore.py", line
2109, in close
block.close()
File "/srv/blah/venv/lib/python2.7/site-packages/fdb/fbcore.py", line
1975, in close
"Error while canceling events:")
fdb.fbcore.DatabaseError: ('Error while canceling events:\n- SQLCODE:
-901\n- invalid events id (handle)', -901, 335545021)
My code is simply:
def loop_on_events(events, handler):
conn = session_db.engine.connect() # using SQLAlchemy,
conn.connection is the raw fdb handle
while True:
with conn.connection.event_conduit(events) as conduit:
actual = conduit.wait(timeout=1)
for e in events:
if actual.get(e, 0) > 0:
current_app.logger.debug('Got event')
handler()
loop_on_events(('result_changed',), handler)
This should just run the handler() (which does other DB operations)
every time the event is triggered.
Is this structure wrong?
thanks
Hamish