Skip to main content

An elegant and simple way to schedule periodic tasks in Python. Both the scheduluer and the task run in the main thread, which avoids the issue of synchronizing the data access between tasks. However, if a task takes a lot of time to complete, the other tasks must wait until it finishes.

ischedule accounts for the time it takes for the task function to execute. For example, if a task is scheduled every second and takes 0.6 seconds to complete, there will be a delay of only 0.4 seconds between consecutive executions. Delays are not propagated. If the previously-mentioned task is scheduled for execution at t=1 second, but is delayed by 0.3 seconds, the next execution of the same task will never the less be scheduled at t=2 seconds.

What happens during heavy loading

  • If more than one task become pending at the same time, they are executed in the order in which they were scheduled by schedule.
  • Regardless of the load, all pending tasks will be executed if they become pending (unless another task hangs).
  • If the execution of a task is delayed that the next execution of the same task become pending, this execution will be skipped.

Exceptions

Exceptions during the execution are propagated out of run_pending, and can be dealth with by the caller.

Example

import time

from ischedule import schedule, run_loop

start_time = time.time()

def job_1():
    dt = time.time() - start_time
    print(f"Started a _fast_ job at t={dt:.2f}")

def job_2():
    dt = time.time() - start_time
    if dt > 2:
        return
    print(f"Started a *slow* job at t={dt:.2f}")
    time.sleep(1)


schedule(job_1, interval=0.1)
schedule(job_2, interval=0.5)

run_loop()

This example produces the following output:

Started a _fast_ job at t=0.10
Started a _fast_ job at t=0.20
Started a _fast_ job at t=0.31
Started a _fast_ job at t=0.41
Started a _fast_ job at t=0.50
Started a *slow* job at t=0.50
Started a _fast_ job at t=1.51
Started a *slow* job at t=1.51
Started a _fast_ job at t=2.52
Started a _fast_ job at t=2.61
Started a _fast_ job at t=2.71
Started a _fast_ job at t=2.81
Started a _fast_ job at t=2.90
Started a _fast_ job at t=3.00

The fast job runs every 0.1 seconds, and completes quickly. When the slow job starts running at t=0.5, it doesn't return control until one second later, at t=1.50s. By that time, both the fast and the slow job become pending, and are executed in the order they were added to the scheduler. The slow job does not run after t=2.0, so the fast job returns to running normally every 0.1 seconds. The task had to be stopped with a keyboard interrupt.

Known issues

None at this time. Issues and suggestions can be submitted to https://github.com/aleksve/ischedule/issues.

Release files for ischedule 0.92

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

Source distribution (sdist)

Source distribution for ischedule 0.92
File Size Uploaded
ischedule-0.92.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ischedule 0.92
File Interpreter ABI Platform
ischedule-0.92-py3-none-any.whl Python 3 none any Details

Total release size: 7.0 kB

Release files / ischedule-0.92.tar.gz

Download URL ischedule-0.92.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fea6449ea03ee6e99920a394c2e933385f761720b109710448a9de0bcd2d9be5
BLAKE2b-256 checksum
How to use checksums
b92fc05576a7dba1180f0d11a358b588fe9a8102755e03c2f29fb1181b2a27b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release files / ischedule-0.92-py3-none-any.whl

Download URL ischedule-0.92-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
416a4fb46d5a43204a951b48b98550707a4d1cde1956ed38feec4d8bc21d8a61
BLAKE2b-256 checksum
How to use checksums
95337a7e2fa7048db57d7a1b305538119bacde5831e29c029e71d995a5e6e768
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release history Release notifications | RSS feed

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

This release

0.92 This release

2 release files

0.91

2 release files

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