项目作者: jdodds

项目描述 :
small python library for running something every n seconds
高级语言: Python
项目地址: git://github.com/jdodds/recurring.git
创建时间: 2018-05-22T08:10:07Z
项目社区:https://github.com/jdodds/recurring

开源协议:MIT License

下载


Recurring

Build Status Coverage Status Documentation Status

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.

Use this if:

  • You want to call something periodically over the lifetime of your application.
  • You want to be able to change the time between calls.
  • You want or need to avoid the overhead of joining and starting a thread every time. (up to 1/5 of a second according to my sample-size of one machine under no other load)
  • The stuff you’re going to call isn’t going to destroy machines if it’s killed abruptly at the end of the application’s life.

This is probably not appropriate for your project if:

  • You’re already using or likely will be using a fleshed-out concurrency framework.
  • You have many things you’d like to repeatedly schedule and run.
  • Your callables absolutely must execute some cleanup code to avoid disaster on kill.

This is not a library intended for top-level program composition.

Installation:

  1. pip install recurring

Usage:

  1. import recurring
  2. def stuff():
  3. # do stuff ...
  4. seconds_between_stuff = 30
  5. job = recurring.job(stuff, seconds_between_stuff)
  6. job.start()
  7. # ...
  8. seconds_between_stuff = 300000000 # this will be *from when rate is set*, not *from the next scheduled call*
  9. job.rate = seconds_between_stuff
  10. # ...
  11. # stop making calls until start() is called again
  12. job.stop()
  13. # some time later ....
  14. job.start()
  15. # stop making calls permanently
  16. job.terminate()
  17. job.start() # raises RuntimeError
  18. job.rate = 3000 # raises RuntimeError