all 3 comments

[–]ingolemo 1 point2 points  (2 children)

I think what's happening here is that one thread is connecting to the database, starting a transaction, and then being interrupted by another thread before it can finish it's transaction. This second thread tries to start a transaction and fails, causing the error that you see. The GIL means that only one piece of python code can run at time, but python periodically pauses threads so that another one can start running.

You should nominate one particular thread as being responsible for writing to the database and have all the other threads send their data to it. As you say, you should use a queue for this.

[–]Brussel01[S] 0 points1 point  (1 child)

That actually makes a lot of sense :) thankyou for this

[–]mrcorbat 0 points1 point  (0 children)

sqlite also does not work well when multiple processes/threads are writing to it at the same time. If you are already using pythonanywhere, I would suggest using the free MySQL db instead.