Skip to main content

async_sched

Use async to have functions run on a schedule.

Example

Async Sched can run tasks on a schedule. It can also receive new tasks (in limited fashion) and change the running schedules without stopping the service.

scheduler.py
schedules/
    task1.py
    task2.py
# scheduler.py
import async_sched

srv = async_sched.start_server(('127.0.0.1', 8000),
                               update_path='./schedules',
                               global_server=True)

# srv.add('3 Second', async_sched.Schedule(seconds=3), print, 'Hello 3 seconds')

srv.run_forever()

Task 1 in the schedules directory will automatically be imported. Because start_server sets the server as an accessible attribute with get_server we can dynamically add schedules.

# schedules/task1.py
from async_sched import get_server, Schedule
import datetime


def print_task1():
    print('Hello! I am task 1 ' + str(datetime.datetime.now()))

s = Schedule(seconds=30, repeat=True)

# This will remove an existing 'Task 1' and schedule a new 'Task 1'
server = get_server()
server.add('Task 1', s, print_task1)

In the task 2 file we are not scheduling any commands, but we are registering a callback function that can be run from a client later.

# schedules/task2.py
from async_sched import get_server, Schedule
import datetime

server = get_server()


@server.register_callback  # or @server.register_callback('print_task2')
def print_task2(name):
    print('Task 2 is running! ', name, str(datetime.datetime.now()))

Now run the scheduler server to listen to remote commands and manage the running schedules.

python scheduler.py

# or python -m async_sched.server.run –path “schedules” –host “127.0.0.1” –port 8000

Use a client to print the running schedules.

python -m async_sched.client.request_schedules –host “127.0.0.1” –port 8000

Reload the files in the ./schedules/ directory.

python -m async_sched.client.update server –host “127.0.0.1” –port 8000

Stop a schedule that is running.

python -m async_sched.client.stop_schedule “Task 1” –host “127.0.0.1” –port 8000

Run a registered callback function.

python -m async_sched.client run_command “print_task2” “hello” –host “127.0.0.1” –port 8000

Schedule a registered command.

python -m async_sched.client schedule_command “print_task2” “hello” –seconds 10 –host “127.0.0.1” –port 8000

Metadata

Release files for async-sched 1.2.5

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

Source distribution (sdist)

Source distribution for async-sched 1.2.5
File Size Uploaded
async_sched-1.2.5.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-sched 1.2.5
File Interpreter ABI Platform
async_sched-1.2.5-py3-none-any.whl Python 3 none any Details

Total release size: 78.0 kB

Release files / async_sched-1.2.5.tar.gz

Download URL async_sched-1.2.5.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0c6e51e4fc1a99ac986bbf4fe6b5b382c04f01e10c7c82584194b068ff03393a
BLAKE2b-256 checksum
How to use checksums
97ad9ff4d09d4171d817489876b42dc3123c0e0e1307dd87b4702ef222a403c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.1

Release files / async_sched-1.2.5-py3-none-any.whl

Download URL async_sched-1.2.5-py3-none-any.whl
Size 60.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a8324994e0a5f0daacdbb3776529693690112b12519d227536079e51e855307
BLAKE2b-256 checksum
How to use checksums
b8782d6a39f1efdf051a12decfdeab09b1d6779947bdff9752eee6c6024c6aed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

1.2.5 This release

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

1 release file

1.1.0

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.0.1

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