^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fix `Cursor.stream()` slowness (:ticket:`#286`).
+- Make `Connection.cancel()` on a closed connection a no-op instead of an
+ error.
Current release
def cancel(self) -> None:
"""Cancel the current operation on the connection."""
+ # No-op if the connection is closed
+ # this allows to use the method as callback handler without caring
+ # about its life.
+ if self.closed:
+ return
+
if self._tpc and self._tpc[1]:
raise e.ProgrammingError(
"cancel() cannot be used with a prepared two-phase transaction"
cur = conn2.execute("select %b", ["hello"])
assert cur.fetchone()[0] == "hellob" # type: ignore[index]
conn2.close()
+
+
+def test_cancel_closed(conn):
+ conn.close()
+ conn.cancel()
cur = await aconn2.execute("select %b", ["hello"])
assert (await cur.fetchone())[0] == "hellob" # type: ignore[index]
await aconn2.close()
+
+
+async def test_cancel_closed(aconn):
+ await aconn.close()
+ aconn.cancel()