Code Monkey home page Code Monkey logo

recurring's Introduction

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:

pip install recurring

Usage:

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

recurring's People

Contributors

jdodds avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.