Do pandas need to close the connection?

When using pandas "read_sql_query" do I need to close the connection? Or should I use the c instruction? Or can I just use the following and be good?

from sqlalchemy import create_engine import pandas as pd sql = """ SELECT * FROM Table_Name; """ engine = create_engine('blah') df = pd.read_sql_query(sql, engine) print df.head() 
+8
python pandas
source share
2 answers

After looking at the source code , I can not find the con.close() method for any SQL connection object, only cursor objects for queries.

I would have escaped to a safe place. Whether you do this with with or not is up to you.

+4
source share

For those who find this question and wonder how to close the connection in this example, the following method worked for me: engine.dispose()

+1
source share

All Articles