aiosqlite icon indicating copy to clipboard operation
aiosqlite copied to clipboard

Aiosqlite leaves thread hanging

Open raees-khan opened this issue 10 months ago • 3 comments

class ProxyClass:
     def __init__(self):
         self._conn = None
         self._connected = False
    
    async def connect(self):
        self._conn = await aiosqlite.connect(':memory:')
        self._connected = True

    def close(self):
        await self._conn.close()
        self._connected = False
   
    def __getattr__(self, name):
        return getattr(self._conn, name)


async def run():
    db = ProxyClass()
    await db.connect()
   try:
        #perform some long running db updates
        #commit changes
   finally:
        await db.close()

I import this in a script and call run using asyncio.run(run()). It finishes but the program never exits because the thread does not get stopped and ctrl+c spits following.

^CException ignored in: <module 'threading' from '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/threading.py'> Traceback (most recent call last): File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/threading.py", line 1448, in _shutdown lock.acquire() KeyboardInterrupt:

raees-khan avatar Apr 05 '24 19:04 raees-khan