How to properly close mysql connections in sqlalchemy? : <p>I would like to know what is <strong>proper</strong> way to close all mysql connections in <code>sqlalchemy</code>. 
For the context, it is a Flask application and all the views share the same <code>session</code> object. </p>

<pre><code>engine = create_engine("mysql+pymysql://root:root@127.0.0.1/my_database")

make_session = sessionmaker(bind=engine, autocommit=False)

session = ScopedSession(make_session)()
</code></pre>

<p>And when the app is teared down, the <code>session</code> is closed and <code>engine</code> is disposed</p>

<pre><code>session.close()
engine.dispose()
</code></pre>

<p>But according to database log, I still have a lot of errors like <code>[Warning] Aborted connection 940 to db: 'master' user: 'root' host: '172.19.0.7' (Got an error reading communication packets)</code>.</p>

<p>I have tried some solutions, including calling <code>gc.collect()</code> and <code>engine.pool.dispose()</code> but without success ... </p>

<p>I suspect there are still some connections opened by the engine behind the scene and they need to be closed. Is there anyway to list all the sessions/connections opened by the engine?</p>

<p>After spending a lot of time on this, any advice/help/pointer will be much appreciated! Thanks.</p>

<p>P.S: the <code>dispose</code> and <code>close</code> calls are inspired from <a href="https://stackoverflow.com/questions/8645250/how-to-close-sqlalchemy-connection-in-mysql">How to close sqlalchemy connection in MySQL</a>. Btw, what is a 'checked out' connection?</p>
