[Python] Should I use scoped_session or open/close connections manually in a desktop app with...

Discussão em 'Python' iniciado por Stack, Janeiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    I’m a beginner programmer and have recently learned how to use Flask and SQLAlchemy to work with databases. While working with Flask, I always used scoped_session, which made sense for managing connections in a web application where multiple requests might come in simultaneously.

    Now, I’m working on a desktop application and I’m wondering about the best practice for managing database connections. Specifically:

    Should I use scoped_session in a desktop app, even though it's not a web app? Alternatively, is it better to open a connection with the engine, perform the database operation, and then close it each time I need to retrieve or modify data? What are the pros and cons of each approach in the context of a desktop application?

    I want to make sure my app is efficient and doesn’t end up leaking database connections or unnecessarily complicating the code.

    Any insights or advice would be greatly appreciated!

    Continue reading...

Compartilhe esta Página