airflow

Use contextlib’s closing context manager:

from contextlib import closing
with closing(connection.cursor()) as cursor:
   # Use cursor here. Will close when it leaves the block.