Skip to main content

sequential-executor

A concurrent.futures.Executor implementation that performs sequential execution.

While this micro-library may seem a little oxymoronic (Executors are, after all, meant to execute calls asynchronously), it does have a fairly well-defined use case.

Use case

A Python package that performs multiple operations via callback(s) defined by implementors using that package. The package allows the implementor to define the concurrent execution environment by passing in a concurrent.futures.Executor object.

This allows the implementor to tailor the execution environment based upon the work that their callback will be performing. For example, if they are making web calls (e.g. - IO bound) they could pass in a ThreadPoolExecutor, but if they are doing numpy analysis of large datasets (e.g. - CPU bound), they could pass in a ProcessPoolExecutor. But what if the implementor must enforce sequential execution, such as for ordered message processing?

The SequentialExecutor provided by this package allows for the implementor using the hypothetical Python package to give that package an Executor, but forces the execution environment into seqential ordering.

Installation

pip install sequential-executor

SequentialExecutor Example

import concurrent.futures
import urllib.request

import sequential_executor

URLS = ['http://www.foxnews.com/',
        'http://www.cnn.com/',
        'http://europe.wsj.com/',
        'http://www.bbc.co.uk/',
        'http://some-made-up-domain.com/']

# Retrieve a single page and report the URL and contents
def load_url(url, timeout):
    print('loading %r' % url)
    with urllib.request.urlopen(url, timeout=timeout) as conn:
        return conn.read()

# We can use in a with statement just like other Executors
with sequential_executor.SequentialExecutor() as executor:
    # Start the load operations and mark each future with its URL
    future_to_url = {executor.submit(load_url, url, 60): url for url in URLS}
    for future in concurrent.futures.as_completed(future_to_url):
        url = future_to_url[future]
        try:
            data = future.result()
        except Exception as exc:
            print('%r generated an exception: %s' % (url, exc))
        else:
            print('%r page is %d bytes' % (url, len(data)))

NOTE - Although this looks like it is submitting multiple jobs and then waiting on each job to complete, the concurrent.futures.Future objects returned by the SequentialExecutor will be fully complete upon the return from the submit call!

Metadata

Release files for sequential-executor 1.0.0

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

Source distribution (sdist)

Source distribution for sequential-executor 1.0.0
File Size Uploaded
sequential-executor-1.0.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sequential-executor 1.0.0
File Interpreter ABI Platform
sequential_executor-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.7 kB

Release files / sequential-executor-1.0.0.tar.gz

Download URL sequential-executor-1.0.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
703b7af8abc595d69a6371345ad4d8092dafba1b30d544c05b27735302d1db18
BLAKE2b-256 checksum
How to use checksums
83f26f514bde07e85dbf473954e78a0e6d23cb1dee2cb19e0f6dcb675c1e63be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release files / sequential_executor-1.0.0-py3-none-any.whl

Download URL sequential_executor-1.0.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56054125c357c6915137e2cde6ec5c1fba102922ad9433b422cdcc0b1f01234a
BLAKE2b-256 checksum
How to use checksums
4e2f015b7e3e5274027bb740ed0dcdccb0c35076c344188cd10dd341da46b169
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release history Release notifications | RSS feed

This release

1.0.0 This release

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