MrPigss / BetterJSONStorage

Better JSONStorage for tinyDB
https://pypi.org/project/BetterJSONStorage/
MIT License
33 stars 4 forks source link

Don't start file write if not needed #4

Closed nielstron closed 1 year ago

nielstron commented 1 year ago

The file writer thread is a 100% CPU usage while loop that checks for file changes. This is questionable already and might be improved by a sleep interjection, but this is for another PR.

This PR simply suggests that if the access mode to the DB is "r" = read-only, then we do not need to run this 100% CPU load thread anyways.

ankraft commented 1 year ago

Are you planning to bring another PR with a sleep injection, or perhaps another solution (Event()?) ?

nielstron commented 1 year ago

I am not sure what kind of solution would generalize best to all use cases. I wrote a simple version that sleeps for 1 second every iteration but can imagine cleaner/simpler/more general ways.

Not planned to make that a PR hence