small python library for running something every n seconds
This is a simple library for running a function or callable every N seconds. It’s meant for applications that need to schedule small, self-contined callable(s) on a relatively long, potentially changing period . alive-checks, state snapshots, that sort of thing.
join
ing and start
ing a thread every time. (up to 1/5 of a second according to my sample-size of one machine under no other load)This is not a library intended for top-level program composition.
pip install recurring
import recurring
def stuff():
# do stuff ...
seconds_between_stuff = 30
job = recurring.job(stuff, seconds_between_stuff)
job.start()
# ...
seconds_between_stuff = 300000000 # this will be *from when rate is set*, not *from the next scheduled call*
job.rate = seconds_between_stuff
# ...
# stop making calls until start() is called again
job.stop()
# some time later ....
job.start()
# stop making calls permanently
job.terminate()
job.start() # raises RuntimeError
job.rate = 3000 # raises RuntimeError