Decorators for running functions in Thread/ThreadPool/IOLoop
Project description
threaded
threaded is a set of decorators, which wrap functions in:
concurrent.futures.ThreadPool
threading.Thread
asyncio.Task in Python 3.
Why? Because copy-paste of loop.create_task, threading.Thread and thread_pool.submit is boring, especially if target functions is used by this way only.
Pros:
Free software: Apache license
Open Source: https://github.com/python-useful-helpers/threaded
PyPI packaged: https://pypi.python.org/pypi/threaded
Tested: see bages on top
Decorators:
ThreadPooled - native concurrent.futures.ThreadPool.
threadpooled is alias for ThreadPooled.
Threaded - wrap in threading.Thread.
threaded is alias for Threaded.
AsyncIOTask - wrap in asyncio.Task. Uses the same API, as ThreadPooled.
asynciotask is alias for AsyncIOTask.
Usage
ThreadPooled
Mostly it is required decorator: submit function to ThreadPoolExecutor on call.
threaded.ThreadPooled.configure(max_workers=3)
@threaded.ThreadPooled
def func():
pass
concurrent.futures.wait([func()])
Usage with asyncio:
loop = asyncio.get_event_loop()
@threaded.ThreadPooled(loop_getter=loop, loop_getter_need_context=False)
def func():
pass
loop.run_until_complete(asyncio.wait_for(func(), timeout))
Python 3.5+ usage with asyncio and loop extraction from call arguments:
loop_getter = lambda tgt_loop: tgt_loop
@threaded.ThreadPooled(loop_getter=loop_getter, loop_getter_need_context=True) # loop_getter_need_context is required
def func(*args, **kwargs):
pass
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait_for(func(loop), timeout))
During application shutdown, pool can be stopped (while it will be recreated automatically, if some component will request).
threaded.ThreadPooled.shutdown()
Threaded
Classic threading.Thread. Useful for running until close and self-closing threads without return.
Usage example:
@threaded.Threaded
def func(*args, **kwargs):
pass
thread = func()
thread.start()
thread.join()
Without arguments, thread name will use pattern: 'Threaded: ' + func.__name__
Override name can be don via corresponding argument:
@threaded.Threaded(name='Function in thread')
def func(*args, **kwargs):
pass
Thread can be daemonized automatically:
@threaded.Threaded(daemon=True)
def func(*args, **kwargs):
pass
Also, if no any addition manipulations expected before thread start, it can be started automatically before return:
@threaded.Threaded(started=True)
def func(*args, **kwargs):
pass
AsyncIOTask
Wrap in asyncio.Task.
usage with asyncio:
@threaded.AsyncIOTask
def func():
pass
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait_for(func(), timeout))
Provide event loop directly:
loop = asyncio.get_event_loop()
@threaded.AsyncIOTask(loop_getter=loop)
def func():
pass
loop.run_until_complete(asyncio.wait_for(func(), timeout))
Usage with loop extraction from call arguments:
loop_getter = lambda tgt_loop: tgt_loop
@threaded.AsyncIOTask(loop_getter=loop_getter, loop_getter_need_context=True)
def func(*args, **kwargs):
pass
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait_for(func(loop), timeout))
Testing
The main test mechanism for the package threaded is using tox. Available environments can be collected via tox -l
CI systems
For code checking several CI systems is used in parallel:
GitHub actions: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests.
coveralls: is used for coverage display.
CD system
GitHub actions: is used for package delivery on PyPI.
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 Distributions
File details
Details for the file threaded-4.2.0.tar.gz
.
File metadata
- Download URL: threaded-4.2.0.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83ad4f3826b465af8b56b373589b13eaebe2733a8772201ce4d1ad2ad2c52515 |
|
MD5 | af2b19a7e3c942fbc253eebba9fe26ae |
|
BLAKE2b-256 | 78a4a89571c3e6c50dfc2087c33680775e66582c6a795237af4d264a63c78d15 |
File details
Details for the file threaded-4.2.0-py3-none-any.whl
.
File metadata
- Download URL: threaded-4.2.0-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38c1a05f30597b45f5fe83d561387626f6f24ff5954567e0a29d90083df22c1b |
|
MD5 | f948bcc70244c2e3f0b5c0203f61d085 |
|
BLAKE2b-256 | 1330e4de40c850009f821892d8a7683c806a43eb2c48a06241f1b087f7546022 |
File details
Details for the file threaded-4.2.0-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 184.8 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca6e8a3cc8886ce7a64eab9c477577220164aee9fdd27decfe20fb5e78e2871 |
|
MD5 | 431c56b613a3d4fe718fff5c09682685 |
|
BLAKE2b-256 | 3e093d650820c9bee7736034e6d2ab084ce42487dcabfbf1f9408e7886a8b30a |
File details
Details for the file threaded-4.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee692bc4e8fd833dad32610342a6a0ede9e5dbd26e080abf56e9f62d322b05a5 |
|
MD5 | 36ab43f8e6eaac17bfab2d7b77c50822 |
|
BLAKE2b-256 | 0d77d94173d6cdcc996989e7ba95cb1998db766a603ae5eff8cf8d7e4c948dfd |
File details
Details for the file threaded-4.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d047f61d8df945af3904a233e094ae7ae285c7baefb97bac2b2ba9cee60d463 |
|
MD5 | a679bd0bb199360aeb2557fa90457cea |
|
BLAKE2b-256 | 3bf09b733946c44a3fd2cc700dcc112ddf18e8078b725a701240fa7439653a00 |
File details
Details for the file threaded-4.2.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: threaded-4.2.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4edbf0ccf76ac77b03334703ed85a8db25185405370c10a493bded70f3572ad3 |
|
MD5 | 2cf1c5f78915d9fb4f91ade632e4964c |
|
BLAKE2b-256 | 2a2bb301e867a25b5629123b840ff8fbc2ab5eedc2e20123482074dd08d43068 |
File details
Details for the file threaded-4.2.0-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 185.4 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04f769a5e5c3c251e64f4cf2c5d099d1327277fd7ab5874749501f1599f65de4 |
|
MD5 | 350e04a538b76094b747c9f0772638aa |
|
BLAKE2b-256 | 422cc284b701df74137f559b4f8b24fdf1fff2c1d95f4a7c2a47d2eb687b13b2 |
File details
Details for the file threaded-4.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ed7419f4409b20b45ec07c8c8dbc59d47f86f8735871b7e1d995b22b548226c |
|
MD5 | 798ce6f703a43459cf1ba73f788931d5 |
|
BLAKE2b-256 | 6279cf488cd0c9b5b167582167d5707e511415567cfdee4950b5108b9d3274c3 |
File details
Details for the file threaded-4.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8bc318d37078af559ccb5fcf63cfb979aa5207fa7a5e6e136aab546762884a4 |
|
MD5 | af4ba5511cad85ffb7108bf3a7df11c8 |
|
BLAKE2b-256 | df520233e4fada165425fac006f63cb7f97a558962dada06e32f4a056d123817 |
File details
Details for the file threaded-4.2.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: threaded-4.2.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14d59d028947221422b480eed89c86aca5a5015d70d59f1508a49c6be179c001 |
|
MD5 | 0b94b0a88407a21dbb71c5c7c408b8ca |
|
BLAKE2b-256 | c6d6db57bd2a5d71a99b966b9fc8bd07f1ad47e327712af0ec1ae8ce958226a3 |
File details
Details for the file threaded-4.2.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 185.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f4360a4ab56ac24450ef5a8696cb8defbdd11b0a9efe8cbc03213776e3d19d6 |
|
MD5 | 3c12488c35f84f9fc06778dece91cf0c |
|
BLAKE2b-256 | dcd046cfd866f7a26bf885d9b422cd1f9d60ceb6d89c3b8372d53539050d275a |
File details
Details for the file threaded-4.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 948.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7550d788bc96e73a70821b481f376f2ebd7afdb40f395651374318cecdebe8e7 |
|
MD5 | fe42db0a042f6da2a8e34a8a78cd0077 |
|
BLAKE2b-256 | ae96812f9b6545ca71c3cb39f732411435ececf6ee8517cee333419b32f34999 |
File details
Details for the file threaded-4.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 942.7 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 289b4b43a3675ddec5fcff189e53b0d42044b61d4fd2241e35ead5abc15db439 |
|
MD5 | 32c625d2b878cb79ccc54c3988f240f8 |
|
BLAKE2b-256 | 109573199a901add89078c9620297cc76aa547e7aed9af77f651874526e2255e |
File details
Details for the file threaded-4.2.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: threaded-4.2.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 910.9 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97418c1029796b35b709915435ea77443ef2565e07ac0c2e2bc6d76a9f013317 |
|
MD5 | f8b9bdb26268a0465feed8b1276e4751 |
|
BLAKE2b-256 | 0b4f47678cf8a27ef168f33f2f9d892ae4252f023aa18e2bb84c8c027c458884 |
File details
Details for the file threaded-4.2.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 188.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbb618a80d79caadd7adfb3dff192681e363871fa12bf3e4ef49ee874e55fa91 |
|
MD5 | 369b3ca14fd33ade57a43359033e84f7 |
|
BLAKE2b-256 | 627b178c1a4a43071617b2e46c1b145171b882329a1b638c775d7edf26f932e4 |
File details
Details for the file threaded-4.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 959.2 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a85db2d603bdb4da5ab6fdd475ade0f56820fe6d191bc647ef68b3983aa2f98 |
|
MD5 | ab68db9d219b64b9e0529069f74e2a89 |
|
BLAKE2b-256 | cc8ac54e1b37c48f31a7e3fc7bea3414f4fff946bba4b25c5ce6e0a5d901516c |
File details
Details for the file threaded-4.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 953.0 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a8839c74e5d88ca7cba346cec394d30e5ec0002e7a59d718df9f2dd331d653d |
|
MD5 | daf6090ebf2dfdfd593f3ddd4aa8c4da |
|
BLAKE2b-256 | 2a5634f80bfffd99493e3da90f66c712b0146dc95d2dea5c0a2b37bd88e2dc70 |
File details
Details for the file threaded-4.2.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: threaded-4.2.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 921.6 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00c1910f722d50e2717ffd5fe8c66e137766eb9c6d78a13992fec11697dc68b0 |
|
MD5 | bcd44e6c686b35dccdbb694765818eaa |
|
BLAKE2b-256 | 2a393ffc37b58df6777a43b7d78578ed960799f764a67967d17be4f1a6274381 |
File details
Details for the file threaded-4.2.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 188.8 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3fde9845f7704110d936687fd2b2b013e0822e5000907e05a900d98fd687ef9 |
|
MD5 | ccd679ac16cccf69c8ded270763a75e2 |
|
BLAKE2b-256 | 74005096b1c2146534c0744e0c7bc443af3936c1017a7c870d2ab32954a845a6 |
File details
Details for the file threaded-4.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 971.9 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b23ff0545f7b6458463c6d9baefee9239b9e6bf721d65099f173a4a5690eba63 |
|
MD5 | c55ba5d827edbac6d33fff5cb8a26e40 |
|
BLAKE2b-256 | abdbbf098374b8231a62914665455ce246143488ad7ad9da8a039b4539537740 |
File details
Details for the file threaded-4.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: threaded-4.2.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 965.8 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93f36eaf4b6880fc373633d2b4740be798d58298ae0b6b6dc598a1ded901922d |
|
MD5 | 7639f26b3100a2a547b34c5e1ece97ef |
|
BLAKE2b-256 | ade16c6ddacf7ad11fb79a506534bd7aaf875a4401d0856161d1d79c6c878a56 |
File details
Details for the file threaded-4.2.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: threaded-4.2.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 938.3 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c52ea5c2d631b64d8f616fc9360320844087fa5257353edc2d360330cbc467d |
|
MD5 | 2732f8da88effa229d878856af9389a8 |
|
BLAKE2b-256 | 5866fddec82a7b565f2420156eb64e1d229ac50d2c1a3515d6bc02c8f52a0245 |