Closed

Description
Is it possible (or sensible) to use the context handler for the connection, e.g.:
connection = pymysql.connect(host='localhost',
user='user',
password='passwd',
db='db',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
with connection as cursor:
... # do something
# proceed
Precisely: Is the connection closed after the with-block? I ask, because
- the example given on https://github.com/PyMySQL/PyMySQL doesn't use the context handler for the connection but for the cursor;
- the exit method of the connection object is
def __exit__(self, exc, value, traceback):
"""On successful exit, commit. On exception, rollback"""
if exc:
self.rollback()
else:
self.commit()
and not
def __exit__(self, exc, value, traceback):
"""On successful exit, commit. On exception, rollback"""
if exc:
self.rollback()
else:
self.commit()
self.close()
Metadata
Metadata
Assignees
Labels
No labels