Principle: The file database SQLite allows multiple processes/threads to read at the same time, but only one thread to write at the same time. During write operations, the database file is deprecated. In this case, any other read/write operations are blocked. If the blocking duration exceeds 5 seconds (the default value is 5 seconds, if you can recompile SQLite to modify the timeout value, the system reports the "database is locked" error.
Therefore, when operating SQLite, you should immediately close the connection; after opening the connection, try to reduce the time-consuming operations as much as possible.
Knowing the principles and precautions does not mean you will not make mistakes. If the following section uses sqlalchemy to operate SQLiteCode:
I believe you will see the problem with this code and understand how to modify it. But I did not make this mistake once, and before I made the same mistake many times, I knew the principle long ago, but still made a mistake. I think it's too rash and casual.