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
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-hypernode.com/pypi/threaded
Tested: see bages on top
Support multiple Python versions:
Python 2.7 PyPy
Decorators:
ThreadPooled - native concurrent.futures.ThreadPool usage on Python 3 and it’s backport on Python 2.7.
threadpooled is alias for ThreadPooled.
Threaded - wrap in threading.Thread.
threaded is alias for Threaded.
Usage
ThreadPooled
Mostly it is required decorator: submit function to ThreadPoolExecutor on call.
threaded.ThreadPooled.configure(max_workers=3)
Python 2.7 usage:
@threaded.ThreadPooled
def func():
pass
concurrent.futures.wait([func()])
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
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:
Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.
coveralls: is used for coverage display.
CD system
Travis CI: 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 Distribution
File details
Details for the file threaded-1.1.2.tar.gz
.
File metadata
- Download URL: threaded-1.1.2.tar.gz
- Upload date:
- Size: 38.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 PyPy/5.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43e21e8ed7fed0a671b7852001c55cbd08de93e9304191ca9eca70be3279c910 |
|
MD5 | a05c9f113ae517b9d889213e8aea12fe |
|
BLAKE2b-256 | 8d9e7fdb1d88fb109f32d573d9d79489797bc38ac5502f9106ecd3a51a059940 |
File details
Details for the file threaded-1.1.2-py2-none-any.whl
.
File metadata
- Download URL: threaded-1.1.2-py2-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 PyPy/5.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eb5ac935c1e08392181093293b0e1a972d62b733b8221ec918d7b22852e5857 |
|
MD5 | 9e065ceeb1f330fe82fe920b3cad1f10 |
|
BLAKE2b-256 | 0c6b60627a7c041c5ca0b5dc1f5678a71f8e69db829fa703956dc6b1ec36b938 |