1

I want to split my TinyDB JSONs to be one per day. I wonder if there is some function to trigger a function call once the day is changed and return to the same spot it was in the code. There is only db.insert in the code so I might want to lock/serialize that part..

For example every day at 00:00:00 time the following function will get called:

change_db():
  db = TinyDB('/stream_' + datetime.date.today() + '.json')
Nir
  • 2,497
  • 9
  • 42
  • 71
  • You probably wouldn’t want your database to change asynchronously at whatever time—just call that function periodically to update the database as needed. – Davis Herring Dec 25 '19 at 18:46
  • I just think it is kind old to check every `x` if the day had changed.. Therefor trigger or listener can be useful. – Nir Dec 25 '19 at 21:02
  • Even with another thread or so sleeping until the right time, you have to have some sort of synchronization with the main processing that needs to know when it changes. Checking the clock instead of a flag is not particularly expensive (if done rarely enough), and it keeps the structure of the code simpler. Things would be different if the main work was just waiting rather than using resources continuously. – Davis Herring Dec 25 '19 at 21:11
  • Since I have only one thread that handle inserts into the db using mutex is the way I was thinking to achieve it. – Nir Dec 25 '19 at 21:31

0 Answers0