[Answered ]-Strange Django behavior with DB insert from separate thread

2👍

The answer seems to be that in memory sqlite databases can’t be shared across threads.

This is a bug report from 1.1 where a core devs concludes it’s not a bug based on SQLAlchemy’s lack of support for it (in the absence of other direct info from sqlite references):

Pysqlite connections do not support being moved between threads,
unless the check_same_thread Pysqlite flag is set to False. In
addition, when using an in-memory SQLite database, the full database
exists only within the scope of a single connection. It is reported
that an in-memory database does not support being shared between
threads regardless of the check_same_thread flag – which means that a
multithreaded application cannot share data from a :memory: database
across threads unless access to the connection is limited to a single
worker thread which communicates through a queueing mechanism to
concurrent threads.

Leave a comment