pyATS Async

26.3 · active · verified Thu Apr 16

pyATS Async is a sub-component of the pyATS ecosystem, a Python-based framework by Cisco specializing in data-driven and reusable network testing and automation. It wraps Python's multiprocessing module to enable asynchronous (parallel) execution of arbitrary functions. The library, currently at version 26.3, is actively maintained with a frequent release cadence, often monthly or bi-monthly.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `pcall` from `pyats.async_` to execute a CPU-bound function across multiple processes in parallel. It includes a synchronous comparison to highlight the benefits of parallel execution for such tasks.

import time
from pyats.async_ import pcall

def my_cpu_bound_task(item):
    """A sample CPU-bound task that simulates work."""
    # print(f"Starting task for item {item}...") # Uncomment to see individual task starts
    time.sleep(1) # Simulate some CPU-intensive work
    result = item * item
    # print(f"Finished task for item {item}, result: {result}") # Uncomment to see individual task finishes
    return result

if __name__ == "__main__":
    items_to_process = [1, 2, 3, 4, 5]

    print("\n--- Running tasks in parallel with pcall ---")
    # pcall executes the function in parallel processes and returns results in order.
    parallel_results = pcall(my_cpu_bound_task, *items_to_process)
    print(f"All parallel tasks completed. Results: {parallel_results}")

    print("\n--- Running tasks synchronously for comparison ---")
    sync_results = [my_cpu_bound_task(item) for item in items_to_process]
    print(f"All synchronous tasks completed. Results: {sync_results}")

view raw JSON →