Skip to content

Aiosqlite leaves thread hanging #290

@raees-khan

Description

@raees-khan
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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions