You can just call cursor.close()
, (or you can do conn.close()
)
From the docs for cursor.close:
r. Closing a cursor cancels the corresponding query and frees the memory associated with the open request.
Additionally, closing the connection itself will automatically close all cursors associated with a connection. In other words, if you're closing connections properly, you usually won't need to explicitly close your cursors.
From the connection.close docs:
Closing a connection normally waits until all outstanding requests have finished and then frees any open resources associated with the connection. By passing false to the noreply_wait optional argument, the connection will be closed immediately, possibly aborting any outstanding noreply writes.