Skip to main content

A lightweight task scheduling timer

Project description

TimerThread

TimerThread is

TimerThread supports to

  • schedule task execution after a given delay
  • schedule recurring task execution
  • run in the background
  • use @task decorator to define task

Quickstart

Define your function, now(cost) as an example:

import time

def now(cost=1):
    time.sleep(cost)
    print( time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime()) )

Create a TimerThread scheduler and start it:

import timerthread

timer = timerthread.Scheduler('recur', 3, now, args=(1,))
timer.start()

Shutdown the scheduler:

timer.cancel()

Play with the @task decorator

Use @task decorator to define your function, then schedule it and start the scheduler, now(cost) as an example:

import time
import timerthread

@timerthread.task('recur', 3)
def now(cost=1):
    time.sleep(cost)
    print( time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime()) )

timer = now.sched(cost=1)
timer.start()

When you'd like to cancel the recurring execution, shutdown the scheduler as usual:

timer.cancel()

Install TimerThread

$ pip install timerthread

Documentation

Scheduler

class timerthread.Scheduler(trigger, interval, fn, args=(), kwargs={})

trigger must be 'delay' or 'recur'.

  • stopped

    The scheduler is stopped or not, True (default) or False.

  • result

    The execution result, {} as default.

  • start()

    Let scheduler start executing your function as scheduled in the background.

  • cancel()

    Shutdown the scheduler.

task

class timerthread.task(trigger, interval)

trigger must be 'delay' or 'recur'.

  • Use @task decorator to define your function, then schedule it and start the scheduler:

    @timerthread.task(trigger, interval)
    def fn(args, kwargs):
        pass
    
    timer = fn.sched(*args, **kwargs)
    

    fn.sched(*args, **kwargs) returns timerthread.Scheduler instance.

Related Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TimerThread-0.1.1.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

TimerThread-0.1.1-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page