async wrapper
Project description
async-wrapper
how to install
$ pip install async_wrapper
# or
$ pip install "async_wrapper[all]"
# or
$ pip install "async_wrapper[anyio]"
# or
$ pip install "async_wrapper[joblib]"
how to use
import asyncio
from aiotools import TaskGroup
# or(>=py311)
# from asyncio.taskgroups import TaskGroup
from async_wrapper import async_to_sync, get_taskgroup_wrapper
@async_to_sync("thread")
async def sample_func() -> int:
await asyncio.sleep(1)
return 1
result = sample_func()
assert isinstance(result, int)
assert result == 1
async def sample_func_2(x: int) -> int:
await asyncio.sleep(1)
return x
async def main():
wrapper = get_taskgroup_wrapper("asyncio")
async with TaskGroup() as task_group:
value_1 = wrapper(sample_func_2, task_group)(1)
value_2 = wrapper(sample_func_2, task_group)(2)
assert isinstance(value_1.value, int)
assert isinstance(value_2.value, int)
assert value_1.value == 1
assert value_2.value == 2
License
MIT, see LICENSE.
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
async_wrapper-0.1.1.tar.gz
(7.2 kB
view details)
Built Distribution
File details
Details for the file async_wrapper-0.1.1.tar.gz
.
File metadata
- Download URL: async_wrapper-0.1.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1040-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8834f702785517d7e5f7be8cc3e0f52b3590829b6b0c4203c3212a5f797ad02f |
|
MD5 | fa0b7d48facf732448c4c220e151a46d |
|
BLAKE2b-256 | 51de097b48e956ffeeefa0646a4239cf62d16c68b00786357029ed3cd63488c2 |
File details
Details for the file async_wrapper-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: async_wrapper-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1040-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bed3372b8522824a82677490758bd54ed3b90f1ff6de67445590fef5c06f128 |
|
MD5 | 7738db43011a7d3ec34468cb39f3fde5 |
|
BLAKE2b-256 | 67d1e7d8ffa166aec86b0a939d79503ab1b224ddf80cda745c315195a2897be8 |