Skip to main content

A very light library to run python functions like cron jobs do.

Project description

A very light library to run python functions like cron jobs do. (support cron expressions with timezone, decorator style, spawn running and graceful exit. Runs in python service like Apscheduler, no effect of system config)

Example

from cron_lite import cron_task, start_all, stop_all, set_time_zone
import time

set_time_zone("Asia/Shanghai")


@cron_task("* * * * * 0/2")
def event1():
    print("event1", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))
    time.sleep(3)
    print("event1 done", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))

@cron_task("* * * * * 0/15")
def event2():
    print("event2", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))
    time.sleep(10)
    print("event2 done", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))


th = start_all(spawn=True)  # use bare `start_all()` to run forever as a service
print("start")
time.sleep(60)
print("stop")
stop_all(th)
print("done")

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

cron-lite-1.1.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file cron-lite-1.1.tar.gz.

File metadata

  • Download URL: cron-lite-1.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for cron-lite-1.1.tar.gz
Algorithm Hash digest
SHA256 f3306c0e67ef96665770a4433b57bf85904eb4524d166d71691b724490954002
MD5 77e666229b63d1e4636b70ffa26bf24a
BLAKE2b-256 dd884958fd7ed033d9be9d888fd127c3bbee5cce879b04e4765bd61947386754

See more details on using hashes here.

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