Skip to main content

concurrent-utils

Project description

Master: travis-master coveralls-master

Develop: travis-develop coveralls-develop


Concurrency utilities for Python 3.7 + asyncio; the main portion is a component abstraction. To support this, some pipe implementations for inter-task, inter-thread, and inter-process communication and some serialization utilities are provided as well. Inter-process communication is based on ZeroMQ.

A “component” is code that is executing on its own, like an asyncio task, a thread, a worker thread’s load, or a process. Components process commands issued by their owner, and create events to be handler by their owner. Components may also produce a result, and of course may communicate with other entities than their owner.

Although asyncio is used heavily, the connection between a workload and its owner decouples the two to allow for any model of concurrency. Here is an example, taken and adapted from the test suite:

import asyncio
from concurrent.futures import ThreadPoolExecutor

from concurrent_utils.component import Component, component_workload, start_component_in_thread


async def test_thread_component_result_success_and_command():
    @component_workload
    async def component(x, *, commands, events):
        await events.send(Component.EVENT_START)
        ### startup complete

        # reply to command
        await commands.send(await commands.recv() + 1)

        # return
        return x

    e = ThreadPoolExecutor(1)
    comp = await start_component_in_thread(e, component, 1)

    assert await comp.request(1) == 2

    assert await comp.result() == 1


asyncio.run(test_thread_component_result_success_and_command())

Although the component is defined as a coroutine, it is (in this case) not executed on the owner’s event loop. The same component could, without modification, be run on the owner’s event loop, or, with minor modifications to make the component function pickle-able, be run in a worker process instead.

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

concurrent-utils-0.1.0.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

concurrent_utils-0.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file concurrent-utils-0.1.0.tar.gz.

File metadata

  • Download URL: concurrent-utils-0.1.0.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0rc1

File hashes

Hashes for concurrent-utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c900769c688155fcfca5e99c32d7013e50812b7c4255be2bd60a49c0966c79f
MD5 6ef3bbe074840a1bb61b00c9b015ac0f
BLAKE2b-256 1e2e943f761cc0b6e62a947217da190139b8247da3e3d2d187c85670d0b806ee

See more details on using hashes here.

File details

Details for the file concurrent_utils-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: concurrent_utils-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0rc1

File hashes

Hashes for concurrent_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11298aaaccd58e74c400379a69035d23e419bdbf5531268bd4db9864f99bd83f
MD5 53982b875fe6021253117557b5a865d7
BLAKE2b-256 31362693611020894136798b487d88699be03770c50524d00bd68aa38012f8a1

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