asyncutor
This package has been renamed to: awaiter.
Makes your blocking functions awaitable.
awaiter.ThreadExecutor() represents a single thread that you can use to execute blocking functions in a FIFO manner.
It does not use a thread pool like asyncio.to_thread() or loop.run_in_executor(), to keep it minimal and predictable.
Usage
import asyncio
import time
from awaiter import ThreadExecutor
def blocking_function(name):
time.sleep(1)
return f'Hello, {name}!'
async def main():
async with ThreadExecutor() as executor:
result = await executor(blocking_function)('World')
print(result)
# out of context, the thread is closed here
if __name__ == '__main__':
asyncio.run(main())
Or use the decorator style:
import asyncio
import time
from awaiter import ThreadExecutor
executor = ThreadExecutor()
@executor
def blocking_function(name):
time.sleep(1)
return f'Hello, {name}!'
async def main():
executor.start()
result = await blocking_function('World')
print(result)
executor.shutdown()
# the thread will be closed.
# if you want to wait until all queued tasks are completed:
# await executor.shutdown()
if __name__ == '__main__':
asyncio.run(main())
If you want to execute multiple tasks at once without waiting in the main thread, use executor.submit():
# ...
fut1 = executor.submit(blocking_function, 'World')
fut2 = executor.submit(blocking_function, 'Foo')
fut3 = executor.submit(blocking_function, 'Bar')
# ...
Last but not least, it also supports generator functions:
# ...
@executor
def generator_function(name):
yield 'Hello, '
time.sleep(1)
yield name
yield '!'
# ...
async for data in generator_function('World'):
print(data)
# ...
But I want a thread pool?
We provide the awaiter.MultiThreadExecutor helper.
It has a thread pool-like approach and is more suitable for use as a single, persistent object:
executor = MultiThreadExecutor(size=10)
How to use is the same, as the interface is identical to awaiter.ThreadExecutor.
Install
python3 -m pip install --upgrade awaiter
License
MIT
Metadata
Release files for asyncutor 0.1.1
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 |
|---|---|---|---|---|
| asyncutor-0.1.1.tar.gz | 3.2 kB | Without provenance | Details for asyncutor-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asyncutor-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for asyncutor-0.1.1-py3-none-any.whl |
Total release size: 6.6 kB
Release files / asyncutor-0.1.1.tar.gz
| Download URL | asyncutor-0.1.1.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c76df91c27d3c0e838c266dbce7e3fccaf561064a8e71b0090dc47c8aa9fa18
|
|
BLAKE2b-256 checksum How to use checksums |
b7b05d3638a2a04d40c52964d3d993706b7d0ff9cf6b1e015bdced2fc8de9680
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.9
|
Release files / asyncutor-0.1.1-py3-none-any.whl
| Download URL | asyncutor-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
797ec3403f0a96909044dec899c062c12d6b62f420300cbb2288a9201552974f
|
|
BLAKE2b-256 checksum How to use checksums |
26bfe99ad25d629a3d8f50a3a6ac2f3d2200ecc3bc84dbea67e19dbc0f3558d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.9
|
Security for asyncutor 0.1.1
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.