code: def test_async_cancel(self):
      async_conn = psycopg2.connect(dsn, async_=True)
      self.assertRaises(psycopg2.OperationalError, async_conn.cancel)
      extras.wait_select(async_conn)
      cur = async_conn.cursor()
      cur.execute("select pg_sleep(10)")
      time.sleep(1)
      self.assertTrue(async_conn.isexecuting())
      async_conn.cancel()
      self.assertRaises(
          psycopg2.extensions.QueryCanceledError,
          extras.wait_select,
          async_conn,
      )
      cur.execute("select 1")
      extras.wait_select(async_conn)
      self.assertEqual(cur.fetchall(), [(1,)])
  
file_path: psycopg2/tests/test_cancel.py
imports: import time
  import threading
  import psycopg2
  import psycopg2.extensions
  from psycopg2 import extras
  from .testconfig import dsn
  import unittest
  from .testutils import ConnectingTestCase, skip_before_postgres, slow
  from .testutils import skip_if_crdb
label_desc: Use image node_id 4 for calling the CancelTests obj's underlying member method code with example usage: obj.test_async_cancel() without return types