Comments (5)
Is this still gonna happen, or is this a dead side project?
from aiotinydb.
Unfortunatelly, it's more of the latter. I intended to use this library in some personal projects, but they got postponed to a halt.
from aiotinydb.
Ok, looks like I'll have to make ZODB aio then
from aiotinydb.
As far as I can tell, a CPU-bound operation in a thread can still block the main event loop, so this requires multiprocessing.
The CPU-bound functions like insert()
, search()
etc. are implemented in the Table
class, which is highly integrated into TinyDB
and Storage
. Implementing this would require writing a wrapper around Table
that executes all methods in another process, which seems to be quite complicated (especially since AIOJSONStorage
can't be pickled). And what if a user wants to use db.insert()
in the main process, but db.search()
should run in a different process? I think such an implementation is just not worth the effort.
With file locking implemented, it's possible to just use another instance of AIOTinyDB
(or even TinyDB
when taking care of filelocking yourself) and run it using a ProcessPoolExecutor
:
def search(filename: str) -> list[Document]:
async def _search():
async with AIOTinyDB(filename) as db:
return db.search(where("foo") == "bar")
return asyncio.run(_search())
async def search_in_process_pool(filename: str) -> list[Document]:
with concurrent.futures.ProcessPoolExecutor() as executor:
return await asyncio.get_event_loop().run_in_executor(executor, search, filename)
Since AsyncIO is more commonly used to avoid performance issues caused by IO operations, I prefer to document that CPU-bound methods such as search()
are blocking and provide an example that shows how multiprocessing can be used. What do you think @ASMfreaK?
(Edit: fixed the example)
from aiotinydb.
Very well written, thanks! We can now close this issue. You can also link it in docs and readme. Should someone come up with a new, better solution, then they should open a new issue.
from aiotinydb.
Related Issues (8)
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 aiotinydb.