Comments (5)
Using multi- processing/threading is not natively supported by TinyDB. It's not specifically mentioned in the docs but it does list it as a reason not to use TinyDB (see here).
It is perfectly possible to use TinyDB with multi- processing/threading but you'll need to put locks in the appropriate places.
In other words this is not a bug, but maybe it should be mentioned in the docs more clearly.
Edit:
I see you use app.run()
, this shouldn't be using more than one thread or process (unless the threaded
or processes
params are set). In short, this should work. Did you use something like gunicorn, uvicorn, ... when running this test? If not then this might indeed be a bug.
from tinydb.
I just ran app.run()
without using gunicorn or anything like that, i just straight up ran python app.py
.
In theory, yes this was not mentioned in the docs which means developers are going to use tinydb in their applications and when deploying to for example namecheaps hosting service, it takes passenger_wsgi.py file which just imports the application from its respective server file and preforms app.run()
. So it only starts one process which is what i initially tested.
app.run()
will in fact start only one process so yeah i think this could be a bug but not entirely sure about it either
If you want me to upload folder where are all the files that i used for testing i will gladly do so.
from tinydb.
Well, when two users send each a HTTP request to the flask server, the server would handle them asynchronously, meaning this opens up for a multi threading. One thread (or request) is trying to preform a write to the db while second thread just started and is behind first thread for 0.02 seconds for example. Than this race condition somehow corrupts the last byte of the db.
This could not be a bug but definitely shall be mentioned in the documentation of the tinydb so that developers can effectively take action to avoid this behavior which causes disruption of service in the end. Especially developers who are trying to implement tinydb on their web applications will find this information crucial as without it, their website is prone to easy DOS with no questions asked!
from tinydb.
i see that you have updated the docs for tinydb v4.8.0 i think. The "Why not use TinyDB" section implies that if you want to use tinydb in HTTP server environment, you should probably look for better solutions. I think this sums it up!
from tinydb.
i see that you have updated the docs for tinydb v4.8.0 i think.
I just looked this up and this sentence has been there since at least v3.0.0 (back in 2015!) 🙂
The point about Flask is correct though. Back when I developed TinyDB, Flask did NOT have multithreading. So it never crossed my mind that using TinyDB with Flask could cause any problems. But since v1.0 in 2018, Flask decided to turn on multithreading by default. I've now updated the documentation to explicitly mention this fact.
from tinydb.
Related Issues (20)
- convert type before matching in query HOT 3
- Query multiple docs by ID HOT 6
- Info on Concurrency HOT 7
- Argument of type "QueryInstance" cannot be assigned to parameter "cond" of type "QueryLike" HOT 2
- Separate File Per Record
- Database corruption when access_mode="a+" and using collection.remove() HOT 1
- Adding query limit 😄
- Empty table does not persist HOT 1
- Modifying documents returned by `search` modifies the query cache
- Can't use lists/dicts as arguments to `Query.test`
- how to flush Tables with CachingMiddleware(JSONStorage)) HOT 2
- de-serialization Query() statement for search is there a way not use eval HOT 3
- Does tinyDB support multi-thread/process access ? HOT 2
- TinyDB 4.8.0 issue HOT 2
- -1073741571 (0xC00000FD) something interesting occured. HOT 2
- Are there any option to persist query caches? HOT 1
- Json decoder error when reading DB from multiple processes HOT 2
- Broken link in documentation.
- is there any way to speed up deletion HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinydb.