Skip to main content

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")

Release files for cron-lite 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cron-lite 1.1
File Size Uploaded
cron-lite-1.1.tar.gz 2.8 kB Details

Release files / cron-lite-1.1.tar.gz

Download URL cron-lite-1.1.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f3306c0e67ef96665770a4433b57bf85904eb4524d166d71691b724490954002
BLAKE2b-256 checksum
How to use checksums
dd884958fd7ed033d9be9d888fd127c3bbee5cce879b04e4765bd61947386754
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

1.1 This release

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page