mercredi 2 décembre 2020

Python: run a function at set interval while program runs

I have a program that will be running 24/7 (assuming no server crashes). The program waits for users of a chat channel to issue commands, then it does several things based on the command issued and user permissions. This program will use and update data from Tuesday 10AM till next Tuesday 9AM, at which point, at 9AM, it will need to wipe the data and start over for the next week cycle.

I'm having trouble finding a way to implement the weekly reset though. I could restart the program every week, but was wondering if there is a way to run a background process that executes a function at a set interval (one week in this case). I was thinking of using a thread to keep track of time, and when a week has passed, have the thread execute the data wipe function. But wouldn't this be an unnecessarily expensive operation? Having a thread running at all times keeping track of passing time seems like a brute force solution.

I would greatly appreciate some pointers on how to go about doing this.

Aucun commentaire:

Enregistrer un commentaire