The following is listed as example in pymysql: conn = pymysql.connect(...) with conn.cursor() as cursor: cursor.execute(...) ... conn.close() Can I use the following instead, or will this leave a lingering connection? (it executes successfully) import pymysql with pymysql.connect(...) as cursor: cursor.execute('show tables') (python 3, latest pymysql) Continue reading...