Unbounded Thread Pool
Implementation of python's concurrent.futures.Executor that creates new threads on demand
and stops them if they are not needed anymore.
It is designed to allow infinite recursive submitting of tasks, so the following code works properly, despite creating of 10k threads:
from unbounded_thread_pool import UnboundedThreadPoolExecutor
with UnboundedThreadPoolExecutor() as executor:
def factorial(n: int):
if n == 0 or n == 1:
return 1
else:
return executor.submit(factorial, n - 1).result() * n
print(factorial(10000))
Installation
pip install unbounded_thread_pool
Requirements
- Python (3.6, 3.7, 3.8)
Usage
UnboundedThreadPoolExecutor supports the following constructor parameters:
name: str: Name of executor, all thread names are prefixed with it. Default isUnboundedThreadPoolExecutor.max_thread_idle_time: float: How many seconds idling worker thread should live. Default is30seconds.
For more details about methods check official python docs about concurrent.futures.Executor.
Usage with asyncio
When you write a lot of sync code that calls async code and vice versa (for example, if you use
asgiref sync_to_async and async_to_sync) default asyncio executor can stuck. It happens
in case you have the following code flow:
async code ---> sync code (1) ---> async code ---> sync code(2)
Here the second (2) sync code requires free worker to be available in thread pool, but
thread pool can be already exhausted by the first (1) sync code. This causes deadlock,
as (1) waits for (2), while (2) waits for (1) to free thread pool. To eliminate this issue,
you can use UnboundedThreadPoolExecutor:
loop = asyncio.get_running_loop()
loop.set_default_executor(UnboundedThreadPoolExecutor(name='AsyncioExecutor'))
Metadata
Release files for unbounded-thread-pool 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unbounded-thread-pool-0.2.0.linux-x86_64.tar.gz | 6.9 kB | Without provenance | Details for unbounded-thread-pool-0.2.0.linux-x86_64.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unbounded_thread_pool-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for unbounded_thread_pool-0.2.0-py3-none-any.whl |
Total release size: 12.2 kB
Release files / unbounded-thread-pool-0.2.0.linux-x86_64.tar.gz
| Download URL | unbounded-thread-pool-0.2.0.linux-x86_64.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2a4e9890b210ab3b6d9283cb4bb27e17f4d929c4b12447780edaceece838ea4
|
|
BLAKE2b-256 checksum How to use checksums |
8a39824bf5b8820114049c95b0f42f56d4c5a544fa8f6b9702f3ffb564853675
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Release files / unbounded_thread_pool-0.2.0-py3-none-any.whl
| Download URL | unbounded_thread_pool-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd349bd0859ef98604b496e8131cec1a28ebfcb0afd844fbae9a1b1e6d7c3847
|
|
BLAKE2b-256 checksum How to use checksums |
4abd7327623d16f52abb0d78281bc961726026f7944c6dfc12f762799b71fd30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Security for unbounded-thread-pool 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.