Skip to content

Spawn threads as daemon so program will exit with main thread. #299

@ethan-vanderheijden

Description

@ethan-vanderheijden

Description

Currently, the threads spawned by aiosqlite's Connection are non-daemon threads, so if you don't explicitly close the connection, the program will stay alive after the main thread exits.

The following aiosqlite code will never exit:

import asyncio
import aiosqlite

async def create_db():
    db = await aiosqlite.connect('../database/partners_list.db')

asyncio.run(create_db())

But the equivalent sqlite code does exit:

import sqlite3

def create_db():
    db = sqlite3.connect('../database/partners_list.db')

create_db()

In my use case, I want to use aiosqlite with Quart, but because I don't want to create a database connection + thread for every request, I will do all my databasing with a single, global connection. However, I'm not sure when the web server will exit and I don't want the program to hang if the database connection hasn't been explicitly closed.

Details

  • OS: Ubuntu 22
  • Python version: 3.10
  • aiosqlite version: 0.20.0
  • Can you repro on 'main' branch? yes
  • Can you repro in a clean virtualenv? yes

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