Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ethan-vanderheijden opened this issue May 30, 2024 · 0 comments
Open

Comments

@ethan-vanderheijden
Copy link

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
smanolloff added a commit to smanolloff/aiosqlite that referenced this issue Oct 28, 2024
Normally, the Connection thread prevents program exit unless
close() is explicitly closed, unless `deaemonic=True` is passed.

It defaults to `False` which means aiosqlite's behaviour remains unaffected.

This PR would also address issues which have been opened for some time now:
omnilib#74
omnilib#299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant