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
Support multiple Python versions:
Python 3.4 Python 3.5 Python 3.6 Python 3.7 PyPy3 3.5+
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()])
Python 3.5+ 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:
Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.
GitHub actions: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests.
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 Distributions
Hashes for threaded-4.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4716455237f688a8f183fd4a6f2134c67046092a6beb73215d808aed3b761804 |
|
MD5 | 0300fdc58171d812d36657b28203ae17 |
|
BLAKE2b-256 | b33920f3189e53c945cb252ef034f0033d800be2fdaead21aa916c8481ea05a8 |
Hashes for threaded-4.1.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79d80de23f67f1d2371df080e3771e3e81ddd6c976317f3905bb1cdd8bf55a5e |
|
MD5 | 3aa6042b623e1f4a4c3d3ffb9c9977c4 |
|
BLAKE2b-256 | 489117a4d5258babf152cdcc711d87963b7da11589c48ebc347b23f5cf3c91f5 |
Hashes for threaded-4.1.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ca1b60a9b222e8fcefb0c7e359044546be0f32577869f0912d627ea0f30f72 |
|
MD5 | d12b1feea1d7cc8ebbbb794fc818ba3f |
|
BLAKE2b-256 | 26148e0505618820546fa5db47ecc6381e1a29bfe2efbd7a345a53da6befbbf6 |
Hashes for threaded-4.1.0-cp39-cp39-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25edeb51a284d9eceea16f4cd7f01c4968eb835b9354e32ece6ffb62b1b0b586 |
|
MD5 | 891fd470cf93173aae1bd315dcb86e1b |
|
BLAKE2b-256 | b3387d55c77f0b083b3b72300a0695e6846c5886d4749cb3f8fda0d910d9f643 |
Hashes for threaded-4.1.0-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac99a572226e938dd4608b439978534376a350aa63d0e1503d167f45b150109d |
|
MD5 | 431d3064179913c12a3bbfe339c2671d |
|
BLAKE2b-256 | 49a467056eb2d121d333178434ceed9977e5fff8cbee9af70e1c4d9d1fe25ea3 |
Hashes for threaded-4.1.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bef9c976f038dfbf9231483b166cd39fdbd550d895062f1f58cac1314e389364 |
|
MD5 | 4fd6169f8e6f0b326d96716b4eae2155 |
|
BLAKE2b-256 | 42059d51b6e0e87b7036fd5f80c98d4aab746b8f05f965006d87359637d30231 |
Hashes for threaded-4.1.0-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc8d09bbc41ddf79a43ed742d049cc456128b5e091065606e03f9eb8664f5bd2 |
|
MD5 | 15a3486bd986e6c9808830ccae60bdbf |
|
BLAKE2b-256 | 9efb73986b964ab970fbfceb19b54c0355c4e220a6cf6ebfd691ce69e40db9a5 |
Hashes for threaded-4.1.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dad9d25e036c2cd51920c25b0db366aa2e30417658ca38b2cfe91998b2a143fe |
|
MD5 | c9a3a109f6b9939d37280e86f2384df3 |
|
BLAKE2b-256 | 5d5091a35d64fe7f943c513123165be6aa5d2c68d2dc0dd3a37c4af03b5feabd |
Hashes for threaded-4.1.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8af7b667b0b1d0bb734043d2b784810b8533c198f5aa86af7780ffbb502d0920 |
|
MD5 | 79fe0ffccf275cd80166ce794fa21d01 |
|
BLAKE2b-256 | 3ec12a35b11a53922dcfa7d2c41d637647dd8a6e5a67d28943b91b4888e5da05 |
Hashes for threaded-4.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5032cf935f97898f5d219646f877df335636167ca812db3bcc9f8a294a5a59b8 |
|
MD5 | cdce74695b8d1dbc49c1b36e06f685f3 |
|
BLAKE2b-256 | 2101239fa59168b15c0af5b5e34c5955c56f8fb88654e111bd9f668e0bfe692a |
Hashes for threaded-4.1.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41d6b39a77c3dad253d12fcc4613b827bbcd57bc1c85dfdfbd18f546d642ba52 |
|
MD5 | 7a340000bcaa37e23178fc957ae932e3 |
|
BLAKE2b-256 | e59fee5ce010efa7c4cf29130c686ff8021a9e4f0628794d582cf7932124d45a |
Hashes for threaded-4.1.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bfe57c4274aa707a198f643dc246a7919711e3c1f96ac17d3914197f1e3f9a0 |
|
MD5 | 48d1326df64b6ba17f8ff1ad7dd095ee |
|
BLAKE2b-256 | 5f215d159a9b90f52d228a124b21be9675d5297839863bb4b9c7b56535e06d1a |
Hashes for threaded-4.1.0-cp38-cp38-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0323eed66abc45a1f332772ee0a8668d0ceb7dea7d0ffc13745033289f5dd3e |
|
MD5 | fddaf284e2814a05d0ce95403bce454f |
|
BLAKE2b-256 | 009e544821f9a7505b9388615384aa4058d74716ad2edb4594519413ddde3286 |
Hashes for threaded-4.1.0-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5720749fd3b1ae549657888fa580d7154c8ff7036dd0c8202affe4eb8708c059 |
|
MD5 | 10c984740ed0f451fadda217d6d8eb3c |
|
BLAKE2b-256 | c34f19b4edcd936a8a2567becd76cec16f7880067f5d30ff65af59d7e3132378 |
Hashes for threaded-4.1.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5ac8bd804ac6d854cf07aca33c73d94a81cb8e84aaa7e783ae7c65a2ee7a787 |
|
MD5 | 7ff0311cdb80b94f6fcafc5eacc3b9e0 |
|
BLAKE2b-256 | 22414cf6e194f7e44cd76f5e4774595f7341d39917297444af90e9abdc3a13ac |
Hashes for threaded-4.1.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31525689a7737a7afb9e37ce38e4944365dc04747f57d8a83c10f35a253744d3 |
|
MD5 | ed18f20bf1c6b10e5e25785024890c5b |
|
BLAKE2b-256 | fd14011d72b38b4b388e5550b3994aa375a814b9dcde62fd3601267843eccd55 |
Hashes for threaded-4.1.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ff3f080b82c29c649ecd5428294880bc8f1abc9732d726d29925d4a944add63 |
|
MD5 | a8cc94a370d1ad292ccefc84bc6ae26b |
|
BLAKE2b-256 | 5cfce98a5e2658fd8285f41457733321be3f9dc0e3656d6a00cfa4ba365f0789 |
Hashes for threaded-4.1.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad28f1c92a0fbf92dc0d1749c04209ad0f726a921537b5b432f8898ffd6a5377 |
|
MD5 | 1bf843ba98b8f4ca91fe546bfaf929dd |
|
BLAKE2b-256 | 54de12becda9e91678bc2a4ddced7a38f2165150a5fc054e0a197022c6695dea |
Hashes for threaded-4.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5f91ea9148752347e62ca8e3cb856d08276856336c1c62d7b7f102f34c2c598 |
|
MD5 | 7b3ac8220b5c377a41e5fcc3e54410b5 |
|
BLAKE2b-256 | 03dc0a0ad18374708714dfad8464ecb35631ff8f48cf9b02cb05e6c7d70d6dba |
Hashes for threaded-4.1.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af19e214c8421ee0fa11b9a054e4d52ab4ccad8cc055f0f9c475fa1438874a14 |
|
MD5 | 7aff1e441a388cfcaf691764a6fd24b8 |
|
BLAKE2b-256 | 07580e80d11a117cf49af9afe15bab0e4b7aa34fa06c2a0bfd188f9cf4387d23 |
Hashes for threaded-4.1.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e230ad33d7eabf69f928d7ed6bf32bbce0b675e6ea61ccd5be4e1f709f2b6fce |
|
MD5 | 36d1004a7c2f722f75b08b827e3a5e2f |
|
BLAKE2b-256 | 94384cbc3b32be1bbef043607516bba653920ad26aa98999d03fec445e5036c1 |
Hashes for threaded-4.1.0-cp37-cp37m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34770786fa06f1b77e32230928ad0cce959e30baa089aac7316da2b113df0d8a |
|
MD5 | a84fd65ffebaf42dd5202b552ea60213 |
|
BLAKE2b-256 | 57c8ed7a84b635db1cd041507ca2afc8ab498d73b24c55d8c14f3c651c4b705b |
Hashes for threaded-4.1.0-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cfeef7ce326613ec02aab281708f7b438ed75694a78ddb6bf5dbbbbf4bb1ca8 |
|
MD5 | 78f0e822d0790bc61318f02c9d0fe2a4 |
|
BLAKE2b-256 | 23a9c6d673a68969ce1c05118f7a7569677f501e73ea3a61fc089594fb2b6579 |
Hashes for threaded-4.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 101c9e0e4b997902a3c7f1892d64af1cbe50535b4738a53008efd2917e6c304e |
|
MD5 | c751b1f261cca7196bd1d60e85392fcd |
|
BLAKE2b-256 | 2a677a14449c9e5aae2b7ff6bb20bad3c546e6ca096b08724ec5ec25196efcfb |
Hashes for threaded-4.1.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f67e20fa18b825a4bb0a5c608ff317bce08315c3cce6b300eb6ec5cc6dc7d654 |
|
MD5 | 264b6e7dbcfa1b7c68e6eb515a841fb9 |
|
BLAKE2b-256 | fa1e9b66db498f771a35f5cbb09bbdb6240c893b2a23b26e53aa83d4d8d60036 |
Hashes for threaded-4.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09f1b660d6653931f47614aaf6b7dd7489dbff4f631b368524ee1fcbac3c1a11 |
|
MD5 | c99e0520bf2b93796d304188cbfbc64a |
|
BLAKE2b-256 | 13e487977aafea1cb6c1f7064f5bd6eaad0f7fadc30c82b21c0bce695c4455c0 |
Hashes for threaded-4.1.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91b486434ad361a58cde711c9916afe0d1c4b1fe43d52b4c225240641d9257bf |
|
MD5 | c201253c2a33ab9b038d36c767b893f4 |
|
BLAKE2b-256 | 5f7652ea04e87da13d9d8ee05324818952ff99c235d2ecebd821f5982e9ff4a3 |
Hashes for threaded-4.1.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adc8191fbfc732b6b8aaad31dc6e394f36ac720e205a02ae1aa03178403d5a80 |
|
MD5 | a626cf6d1c148afb8ae11fbe62042605 |
|
BLAKE2b-256 | e4a1cc9592e49395957a69806e7cc4ff10c0873383c98b7cb3e806ea05f7c8b7 |
Hashes for threaded-4.1.0-cp36-cp36m-manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76d05c4042511451d4db93d7cd80abd32795ffdb9d5cdf975e6311e65d7bf709 |
|
MD5 | 57efba8878ebf40032203cf50f1f8a0c |
|
BLAKE2b-256 | fa2fd727c0eed7a237034bdaa3063f0268a77baca0c8caf82da0801adc5946a0 |
Hashes for threaded-4.1.0-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c42301f59c9377404e070506d26b9532b47e984c22de254d8cbed2c35949567f |
|
MD5 | 36cfa65bbd8660a1db1e153373b87f60 |
|
BLAKE2b-256 | 5c2f140f4d64ec726a868742686561508f262c9df5acedf77f1744650c4ddfbf |
Hashes for threaded-4.1.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df67a80af4e268eb66e7cdce2760b78b57d073f34948b1f66a9007ea42e9805c |
|
MD5 | 66eaa83399c2b4423413f6279617b2aa |
|
BLAKE2b-256 | fd2589eedd4f3d2ff0252e45f317d727db484633624c4872f7cf355dcce735d3 |
Hashes for threaded-4.1.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1476bcf22f8e014585b0dd4b3459a386303a796abeea5d03a3c7b17aed2127a9 |
|
MD5 | d83de2012c001906585b36985e82f98a |
|
BLAKE2b-256 | e13a3751e780354297cbe8798fddfb3fe340481d79cc78c01d6cb4bbce8a5ba4 |
Hashes for threaded-4.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b6bc80e852de468f35d17f710baefc6210825021f6ef77efefb1dac471c8f9a |
|
MD5 | efc0a3a21ab23d3e68a9f747ea51e51c |
|
BLAKE2b-256 | ee283d6449c505322c62e134660142017de7105bcd80a5d74dc32f7f5a80ccbd |
Hashes for threaded-4.1.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27c89302f1e98775a4e8ed4b3a1e982940c5615d857b5971791c2ecc344c3aee |
|
MD5 | 3490a6eb86c643e3c88bc984064e5d5e |
|
BLAKE2b-256 | 929c14b7fcf21f5429ab3d86120926fe1b42bf5df6e2ff348a08b24ec0776e1c |