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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file concurrently-1.1.post1.dev1.tar.gz
.
File metadata
- Download URL: concurrently-1.1.post1.dev1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d08bd4ead6b22f44684af26f0cf23cedfcb4e26d7649fcd457a9e37d8821fe3 |
|
MD5 | ddea407aa464938d5204649cf905bf82 |
|
BLAKE2b-256 | d679c2bfd6b24e8774262cfcb74d202953e1f3a1dc8b19b3d8b29c5a9239d5fb |
File details
Details for the file concurrently-1.1.post1.dev1-py3-none-any.whl
.
File metadata
- Download URL: concurrently-1.1.post1.dev1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbd17ace854c683b5f4e688146468816efd93b5adc3c040baf512122a5988d41 |
|
MD5 | 8f9347b15b23faea3234535231851c0f |
|
BLAKE2b-256 | 4f98cf4c50ec9aaab2aca71d49756921d9667cb8bc4894e739b3a72e6ade9b2b |