Skip to main content

Library helps easy write concurrent executed code blocks

Project description

Concurrently

Library helps to easily write concurrent executed code blocks.

Quick example:

import asyncio
from concurrently import concurrently


async def amain(loop):
    """
    How to fetch some web pages with concurrently.
    """
    urls = [  # define pages urls
        'http://test/page_1',
        'http://test/page_2',
        'http://test/page_3',
        'http://test/page_4',
    ]
    results = {}

    # immediately run wrapped function concurrent
    # in 2 thread (asyncio coroutines)
    @concurrently(2)
    async def fetch_urls():
        for url in urls:
            # some function for download page
            page = await fetch_page(url)
            results[url] = page

    # wait until all concurrent threads finished
    await fetch_urls()
    print(results)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(amain(loop))
Decorator @concurrently makes to main thinks:
  • starts concurrent execution specified count of decorated function

  • returns special waiter object to control the running functions

By default, the code runs as asyncio coroutines, but there are other supported ways to execute, by specifying the argument engine.

Documentation

See https://concurrently.readthedocs.io/

Requirements

Now support only Python 3.5 and above.

Install

From PyPi:

$ pip install concurrently

From local:

# update setuptools
$ pip install 'setuptools >= 30.4'
# do install
$ make install
# or
$ pip install .

Development

Prepare and activate virtual environment like:

$ python3 -m venv .env
# for bash
$ source .env/bin/activate
# for fish
$ . .env/bin/activate.fish

Update pre-install dependencies:

$ pip install 'setuptools >= 30.4'

Install:

$ make install_dev
# or
$ pip install --editable .[develop]

Run tests:

$ make test
# or
$ pytest tests/

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

concurrently-0.12.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

concurrently-0.12-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file concurrently-0.12.tar.gz.

File metadata

  • Download URL: concurrently-0.12.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for concurrently-0.12.tar.gz
Algorithm Hash digest
SHA256 864602beb4f0651dcca752c44a6e501b1b65ffa3a6fcc32c5d65e6c00050c3af
MD5 046da24fdb2e14053d476ff2f3f77a0c
BLAKE2b-256 358d32e41e93584998928d0dc55a0da3bae73d745603080f95f506efafcb3738

See more details on using hashes here.

File details

Details for the file concurrently-0.12-py3-none-any.whl.

File metadata

  • Download URL: concurrently-0.12-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for concurrently-0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 ffb68178c7be020a91bdee25e49682f07606b37cf0e9f489a34a2ff6353f60eb
MD5 7e261f7c38a7c0c6485b9a188d6f1ea6
BLAKE2b-256 063e7b53d3678f690a7eb664549ba4dc197bd920057bbf8a9b3e02146fb04500

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