Closed patecone closed 1 year ago
Fundamentally, each connection can only do one DB operation at a time (see footnote below), so if you want to be doing multiple things you will need to have multiple connections open, and do each operation (listening, sending queries) on different connections. Generally using a SessionPool is a good idea.
Your error sounds like something in the architecture isn't quite right.
Footnote: Oracle Database 23c supports pipelining at the C interface, but this hasn't been exposed to Python. The asyncio support planned for python-oracledb mode will probably be done differently, particularly because python-oracledb Thin mode doesn't use the Oracle Database C libraries.
Fundamentally, each connection can only do one DB operation at a time (see footnote below), so if you want to be doing multiple things you will need to have multiple connections open, and do each operation (listening, sending queries) on different connections.
Your error sounds like something in the architecture isn't quite right.
Thank you @cjbj, following your comment I gave a long good look to the architecture. You were right, something wasn't quite right. Just for the records - hoping it might help somebody playing with Alchemy and Queues - I think the issue was on the connection handling.
I mean, first I chose to leave the ORM framework manage active connections, so I had no control on which connection was used to dequeue a message or to fire a query. This seems to enable some sort of connection sharing/reuse between dequeueing and selecting. Probably SQLAlchemy doesn't trace dequeueing ops so the connection seems available for reuse. This might trigger the exception.
By explicitely acquiring a connection from the pool (even without refactoring with cx_Oracle.SessionPool
) I've seen no execption in the last 12 hour.
I think this closes the issue. Ciao
my question is about an application I'm trying to build which is supposed to:
a. dequeue message from a single consumer oracle AQ (using cx_Oracle AQ support) b. carry out scheduled tasks that involve querying the database (using APScheduler on top of an asyncio.loop) c. serve some REST requests coming from the outside world (using a simple HTTPServer running in a separate Thread)
the issue I'm facing is that if any of task a or b fires a select statement while dequeue is running - especially if I set
DEQ_WAIT_FOREVER
- I get the following errorsFull traceback example:
Now I don't need, nor I want, to make the app fully async, all I want is to be able to dequeue messages, either by using a high frequency scheduled task or a while loop, and fire database queries safely.
As you may have noticed in my example the connection is provided by
sqlalchemy.pool.impl.QueuePool
, but I have already checked that I might usecx_Oracle.SessionPool
as connection pooling implementation (supported by SQLAlchemy) so what I'm really questioning is if cx_Oracle does support dequeue operation and queries concurrently.I haven't tried using
cx_Oracle.SessionPool
so far because I have a lot of queries all over the app and I'd like to be sure it solves my queue issue before taking the risk of refactoring.Any comment suggestion much appreciated.
Cristiano