Skip to main content

GUI-friendly library for scheduling processes using coroutines.

Project description

Async Process Scheduler

License: MIT PyPI PyPI - Python Version

Current status: beta.

Introduction

Async Process Scheduler is a small Python library which provides a simple, GUI-friendly way to efficiently run many processes while avoiding a callback-based data flow.

Async Process Scheduler is compatible with multiprocessing from the standard library, and equivalent implementations such as multiprocess.

Note: To use Async Process Scheduler in a GUI program, you'll need a library which implements a compatible event loop. For example, asyncqt can be used with PyQt5.

Installation

To install Async Process Scheduler, use pip:

pip install AsyncProcessScheduler --user

Usage

To use Scheduler in Python, import from scheduler:

from scheduler.Scheduler import Scheduler

After adding processes to a Scheduler instance, running the processes and getting their results is simple:

results: List[Tuple] = await Scheduler.run()

Detailed examples are in the examples folder, including a GUI example using PyQt5. Here is a code snippet which shows the general workflow:

def long_calculation(queue: Queue):
    time.sleep(5) # Simulate a long calculation.
    queue.put((
        "x", "y", "z" # These values will be returned by the scheduler for each process.
    ))


async def run():
    scheduler = Scheduler()
    num_processes = 16

    for i in range(num_processes):
        queue = Queue()
        process = Process(target=long_calculation, args=(queue,))

        scheduler.add(process, queue)

    # Run all processes and get an ordered list containing the results from each.
    results: List[Tuple] = await scheduler.run()

    # Do something with the results.
    print(results)

# Start the coroutine.
asyncio.ensure_future(run()) 

Design

This diagram demonstrates the implementation of Scheduler.

Image demonstrating the design of Scheduler.

Developer notes

Packaging the project

From the documentation:

rm -r dist/
python setup.py sdist
python setup.py bdist_wheel
twine upload dist/*

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

AsyncProcessScheduler-0.3.0b1.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

AsyncProcessScheduler-0.3.0b1-py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 3

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