Menu Close

How to fix ProgrammingError: SQLite objects created in a thread can only be used in that same thread with Python SQLite3?

Sometimes, we want to fix ProgrammingError: SQLite objects created in a thread can only be used in that same thread with Python SQLite3

In this article, we’ll look at how to fix ProgrammingError: SQLite objects created in a thread can only be used in that same thread with Python SQLite3.

How to fix ProgrammingError: SQLite objects created in a thread can only be used in that same thread with Python SQLite3?

To fix ProgrammingError: SQLite objects created in a thread can only be used in that same thread with Python SQLite3, we can call sqlite3.connect with check_same_thread set to False.

For instance, we wrikte

conn = sqlite3.connect('your.db', check_same_thread=False)

to call sqlite3.connect with the check_same_thread set to False so that SQLite objects created in any thread can be used in any other thread.

Conclusion

To fix ProgrammingError: SQLite objects created in a thread can only be used in that same thread with Python SQLite3, we can call sqlite3.connect with check_same_thread set to False.

Posted in Python, Python Answers