How to use cx_Oracle session pool with Flask gracefuly?
NickName:taoeaten Ask DateTime:2018-01-30T17:06:00

How to use cx_Oracle session pool with Flask gracefuly?

I'm a newbie to Python and Flask, and I use Oracle, when learning Flask tutorial, I code as follow, but it smells really bad, please help me with these questions, thanks a lot!

1) need I release connection to poll explicitly?

2) how can I implement poll acquire and release gracefully?

def get_dbpool():
if not hasattr(g, 'db_pool'):
    g.dbPool = connect_db()
return g.dbPool

@app.teardown_appcontext
def close_db(error):
    if hasattr(g, 'db_pool'):
        g.dbPool.close()

@app.route('/')
def hello_world():
    db = get_dbpool().acquire()
    cursor=db.cursor()
    sql=''
    cursor.execute(sql)
    rows = cursor.fetchall()
    cursor.close()
    get_dbpool().release(db)
    return json.jsonify(combines=rows)

Copyright Notice:Content Author:「taoeaten」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48517547/how-to-use-cx-oracle-session-pool-with-flask-gracefuly

More about “How to use cx_Oracle session pool with Flask gracefuly?” related questions

How to use cx_Oracle session pool with Flask gracefuly?

I'm a newbie to Python and Flask, and I use Oracle, when learning Flask tutorial, I code as follow, but it smells really bad, please help me with these questions, thanks a lot! 1) need I release

Show Detail

Issue in DB pooling using cx_oracle and Flask (Python)

We have develoed an APP using Angular 8 and flask-restplus(0.13.0) (Python 3.7.4) and cx_oracle(7.2.3). The Angular app is deployed on NGINX on Ubuntu server. We have created 3 micro services and h...

Show Detail

Issue in DB pooling using cx_oracle and Flask (Python)

We have develoed an APP using Angular 8 and flask-restplus(0.13.0) (Python 3.7.4) and cx_oracle(7.2.3). The Angular app is deployed on NGINX on Ubuntu server. We have created 3 micro services and h...

Show Detail

Insert values to the oracle table using python cx_oracle Session Pool

Can any one help how to insert a single row into the oracle table using the python cx_oracle Session Pool? I am seeing some issue with the below code. Type error: expecting string or object Name N...

Show Detail

How to create a connection (or session) pool in python multiprocessing code using cx_Oracle to connect to a Oracle database?

I have a very lengthy multiprocessing python code which involves interaction with the Oracle database several times during the run. The code is supposed to be an independent application which will ...

Show Detail

How do I run cx_Oracle queries within my session limit?

I am querying an Oracle database through cx_Oracle Python and getting the following error after 12 queries. How can I run multiple queries within the same session? Or do I need to quit the session ...

Show Detail

Is there any way to acquire a connection from session pool with SYSDBA privileges?

When connecting using cx_oracle.connect there is a parameter mode=cx_Oracle.SYSDBA but I could not find any way of specifying the same with session_pool when I try to give session_pool to conne...

Show Detail

Flask: how to use cx_Oracle.SessionPool created once in __init.py__.create_app() in routes (other .py files)

I have a simple Flask app like this : simple_app/lib/oracle.py: import cx_Oracle from flask import current_app def create_pool(): # Create session pool pool = cx_Oracle.SessionPool(user=

Show Detail

cx_Oracle SessionPool root of all Flask problems

I created a web service in Flask over uwsgi. I thought I would follow good practice and create a SessionPool with 20 connections to be safe. Each call to a web service endpoint, I acquire a conne...

Show Detail

Correct use of sqlalchemy sesion with Flask

I am trying to use sqlalchemy with flask(without the flask-sqlalchemy extension). I am struggling with how to integrate the session object of sqlalchemy with flask. I have seen several approaches:...

Show Detail