Answer the question
In order to leave comments, you need to log in
How to close all valid connections in sqlite3?
How it is possible to close ALL connections. Not a single, but all connections.
Found with django, but it doesn't work.
from django import db
db.connections.close_all()
Answer the question
In order to leave comments, you need to log in
The above code with django works because django has information about all connections opened by django and can close them.
With the direct opening of bases, of course, information about them does not add up anywhere. To get this on your own, you can put the connection in the list every time you open the sqlite database, and at the right time iterate over it and close everything:
db_connections = []
db1 = sqlite3.connect('baza1.db')
db_connections.append(db1)
db2 = sqlite3.connect('area51.db')
db_connections.append(db2)
...
for db in db_connections:
db.close()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question