P
P
pcdesign2017-09-17 09:49:40
Flask
pcdesign, 2017-09-17 09:49:40

Is there an option to completely close the connection to mysql?

SQLAlchemy constantly maintains a connection to the database.
Is there any way to make the connection close after the application is executed?
I tried to do like this:

@app.teardown_appcontext   
def shutdown_db(exception=None): 
    db.session.remove()
    db.session.close()

But I look with the help of lsof -i, all the same, the connection to the database is not killed.
python  6508     myflask    8u  IPv4 495690      0t0  TCP localhost:36322->localhost:mysql (ESTABLISHED)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2017-09-17
@pcdesign

@app.teardown_appcontext
def shutdown_session(exception=None):
    db.session.remove()
    db.session.close_all()
    db.engine.dispose()

This is how the connection with mysql is tightly killed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question