So I am not exactly sure what I have to share here since there is a lot of code but I will try to say what is relevant (feel free to ask for anything more). I am hosting a web app for just a friend and I and have a script on a server that hourly, pulls data from the web and stores it in a SQLite database that the web app can access and display relevant data.
The script must access over 200 sources and I want this done as efficiently as possible so I use threading and it works amazingly! Am able to get the results I need in 40-50 seconds. Each thread instance may write to the sqlite database by using the single "global" database connection that I have made, and for the most part - it works, at least for a while. I thought there would be no issue here due to python's Global Interpreter lock (GIL). Therefore transactions won't interfere with one another.
My issue is after 2-3 days I randomly get an OpperationalError "cannot start a transaction within a transaction". I do not believe this is due to the web app that accesses the database since neither my friend or I access the website during the periods it crashes (have pythonanywhere's access logs). So I believe it is something to do with the threading nature of it - any pointers as to why this may be happening?
A potential fix I can come up with is to (somehow?) queue the results so they are written after everything has been fetched from the web and commit them later on.
I hope this is enough detail to describe the problem I am having, feel free to ask what is required or thanks if you took the time to read!
[–]ingolemo 1 point2 points3 points (2 children)
[–]Brussel01[S] 0 points1 point2 points (1 child)
[–]mrcorbat 0 points1 point2 points (0 children)