Skip to main content

Asynchronous task scheduler and runner for Python

Project description

BuildStatus Coverage

Task scheduler based on asyncio. Allows max-concurrency and granularity to be specified. Execution results are printed as a Gantt chart.

Sample Usage

from asynctasks.executor import Executor
from asynctasks.executionplan import ExecutionPlan
import asyncio

#create an array of tasks
tasks_dict_array = [{"dependencies": [], "name": "task0"}, {"dependencies": [0], "name": "task1"},
                        {"dependencies": [1], "name": "task2"}, {"dependencies": [0], "name": "task3"},
                        {"dependencies": [], "name": "task4"}, {"dependencies": [], "name": "task5"}]

#define an async function that should be executed for each task
async def print_task(loop, task):
   print("Executing task {}".format(task))
   await asyncio.sleep(0.1)

#create an execution plan for the tasks
plan = ExecutionPlan().from_dict_array(tasks_dict_array)
print("\nBEFORE EXECUTION\n{}".format(plan))

#execute the plan with print_task function and max_concurrency as 2
Executor(plan, 2, 0.01, print_task).trigger_execution()
print("\nAFTER EXECUTION\n{}".format(plan.as_gantt()))

Sample Output

BEFORE EXECUTION
task0 Ready
    task1
        task2
    task3
task4 Ready
task5 Ready

Executing task {'dependencies': [], 'name': 'task0', 'start_time': 1497528994.1246588}
Executing task {'dependencies': [], 'name': 'task4', 'start_time': 1497528994.1246588}
Executing task {'dependencies': [0], 'name': 'task1', 'start_time': 1497528994.236074}
Executing task {'dependencies': [0], 'name': 'task3', 'start_time': 1497528994.2370954}
Executing task {'dependencies': [1], 'name': 'task2', 'start_time': 1497528994.340769}
Executing task {'dependencies': [], 'name': 'task5', 'start_time': 1497528994.3417716}

AFTER EXECUTION
      ....................................................................................................
task0 ...............................
task1                                   .............................
task2                                                                    ................................
task3                                    .............................
task4 ...............................
task5                                                                     ...............................

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

asynctasks-0.1.4-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file asynctasks-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for asynctasks-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8f10a2cb323a4f7e7cabf05b2987ebdb7647991efec626c17a530a6f441c742c
MD5 fbe6a0bb0d2dbfebc525aa65c148f26e
BLAKE2b-256 2ff7974d6b73323efc90e117936c36ca68ed6017668aa6766c21b24ac90cb2c1

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