easy to covert between sync and async
Project description
revolving_asyncio
同步异步互转工具
- 本项目依赖于nest_asyncio 在嵌套场景下,需要对
asyncio
打补丁 - 本项目提取于ksrpc 中的同步异步任意转换功能
Installation安装
pip install revolving_asyncio -U
Usage使用
See more examples
import asyncio
import time
from revolving_asyncio import to_async, to_sync
if __name__ == '__main__':
@to_async
def do_sync_work(name: str):
time.sleep(5)
print(f"sync function, to async by decorator, {name}")
async def do_async_work(name: str):
await asyncio.sleep(5)
print(f"async function, to sync by wrapper, {name}")
async def async_main():
# Method 1
await do_sync_work(name="Method 1")
def sync_main():
# Method 2
to_sync(do_async_work)(name="Method 2")
asyncio.run(async_main())
sync_main()
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
Close
Hashes for revolving_asyncio-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cee5f612e54dca2e8054bffd9d19e728f35eee13496d3ab2c8576de6807d57b0 |
|
MD5 | bf8b2b1bd8567f19f87d52073efe63b7 |
|
BLAKE2b-256 | d22f3d5f7d5368102c0447d8514357bd759356831804d41ccfae69ca41c90bb2 |