connect_async hangs when connecting to Autonomous DB 19c in OCI #277
-
| Problem: OS: MacOS Ventura 13 import getpass import sys import oracledb import os import asyncio dsn = os.environ.get('ORACLE_DSN') pw = os.getenv("ORACLE_PW") or getpass.getpass("Enter password: ") assert dsn is not None async def async_main(): connection = await oracledb.connect_async( user="scott", password=pw, dsn=dsn, ) print("version: " + connection.version) cursor = await connection.cursor() # Create a table await cursor.execute(""" begin execute immediate 'drop table todoitem'; exception when others then if sqlcode <> -942 then raise; end if; end;""") await cursor.execute(""" create table todoitem ( id number generated always as identity, description varchar2(4000), creation_ts timestamp with time zone default current_timestamp, done number(1,0), primary key (id))""") # Insert some data rows = [ ("Task 1", 0 ), ("Task 2", 0 ), ("Task 3", 1 ), ("Task 4", 0 ), ("Task 5", 1 ) ] await cursor.executemany("insert into todoitem (description, done) values(:1, :2)", rows) print(cursor.rowcount, "Rows Inserted") await connection.commit() cursor.close() connection.close() async def sync_main(): connection = oracledb.connect( user="scott", password=pw, dsn=dsn, ) print("version: " + connection.version) cursor = connection.cursor() # Create a table cursor.execute(""" begin execute immediate 'drop table todoitem'; exception when others then if sqlcode <> -942 then raise; end if; end;""") cursor.execute(""" create table todoitem ( id number generated always as identity, description varchar2(4000), creation_ts timestamp with time zone default current_timestamp, done number(1,0), primary key (id))""") # Insert some data rows = [ ("Task 1", 0 ), ("Task 2", 0 ), ("Task 3", 1 ), ("Task 4", 0 ), ("Task 5", 1 ) ] cursor.executemany("insert into todoitem (description, done) values(:1, :2)", rows) print(cursor.rowcount, "Rows Inserted") connection.commit() cursor.close() functions = {'async_main': async_main, 'sync_main': sync_main} choice = 'sync' if (len(sys.argv) == 2): choice = sys.argv[1] coro = functions[f'{choice}_main']() asyncio.run(coro) With this script, set ORACLE_DSN to oracle net format DSN you get from OCI, and ORACLE_PW to password. But async version hangs If I press I suppose this may have to do with some protocol peculiarity. I can provide test ADB credentials over DM if needed. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
| I am unable to reproduce the hang myself using the credentials you provided. Can you set the environment variable |
Beta Was this translation helpful? Give feedback.
I am able to reproduce with Python 3.10 and lower. Python 3.11 and higher do not experience a hang. The uvloop alternative implementation also works without trouble.