Name | revolving-asyncio JSON |
Version |
0.1.2
JSON |
| download |
home_page | None |
Summary | easy to covert between sync and async |
upload_time | 2025-09-13 16:58:24 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6 |
license | MIT |
keywords |
async
asyncio
sync
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# revolving_asyncio
同步异步互转工具
1. 本项目部分依赖于[nest_asyncio](https://github.com/erdewit/nest_asyncio), 在嵌套场景下,可能需要对`asyncio`打补丁
2. 本项目提取于[ksrpc](https://github.com/wukan1986/ksrpc) 中的同步异步任意转换功能
## Installation安装
```commandline
pip install revolving_asyncio -U
```
## Usage使用
See more [examples](examples)
```python
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()
```
## Exception 异常
如果直接使用`to_async`和`to_sync`报`RuntimeError: This event loop is already running`等一类的异常,
可以尝试添加以下代码
```python
import revolving_asyncio
revolving_asyncio.apply()
```
Raw data
{
"_id": null,
"home_page": null,
"name": "revolving-asyncio",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "async, asyncio, sync",
"author": null,
"author_email": "wukan <wu-kan@163.com>",
"download_url": "https://files.pythonhosted.org/packages/72/5f/3f10e4a28f6b23e3d7caa00070dfdd4467b946e16a495998c2450eaf40b5/revolving_asyncio-0.1.2.tar.gz",
"platform": null,
"description": "# revolving_asyncio\n\u540c\u6b65\u5f02\u6b65\u4e92\u8f6c\u5de5\u5177\n\n1. \u672c\u9879\u76ee\u90e8\u5206\u4f9d\u8d56\u4e8e[nest_asyncio](https://github.com/erdewit/nest_asyncio), \u5728\u5d4c\u5957\u573a\u666f\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u5bf9`asyncio`\u6253\u8865\u4e01\n2. \u672c\u9879\u76ee\u63d0\u53d6\u4e8e[ksrpc](https://github.com/wukan1986/ksrpc) \u4e2d\u7684\u540c\u6b65\u5f02\u6b65\u4efb\u610f\u8f6c\u6362\u529f\u80fd\n\n## Installation\u5b89\u88c5\n```commandline\npip install revolving_asyncio -U\n```\n\n## Usage\u4f7f\u7528\nSee more [examples](examples)\n```python\nimport asyncio\nimport time\n\nfrom revolving_asyncio import to_async, to_sync\n\nif __name__ == '__main__':\n @to_async\n def do_sync_work(name: str):\n time.sleep(5)\n print(f\"sync function, to async by decorator, {name}\")\n\n\n async def do_async_work(name: str):\n await asyncio.sleep(5)\n print(f\"async function, to sync by wrapper, {name}\")\n\n\n async def async_main():\n # Method 1\n await do_sync_work(name=\"Method 1\")\n\n\n def sync_main():\n # Method 2\n to_sync(do_async_work)(name=\"Method 2\")\n\n\n asyncio.run(async_main())\n sync_main()\n\n```\n\n## Exception \u5f02\u5e38\n\u5982\u679c\u76f4\u63a5\u4f7f\u7528`to_async`\u548c`to_sync`\u62a5`RuntimeError: This event loop is already running`\u7b49\u4e00\u7c7b\u7684\u5f02\u5e38\uff0c\n\u53ef\u4ee5\u5c1d\u8bd5\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\n\n```python\nimport revolving_asyncio\nrevolving_asyncio.apply()\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "easy to covert between sync and async",
"version": "0.1.2",
"project_urls": null,
"split_keywords": [
"async",
" asyncio",
" sync"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "61fdfce42c63ff370ec1a2947948c93393ea1aaf76c88345e5716bbb344f43e9",
"md5": "fd2e11046fb800c9d60b06aefac4673f",
"sha256": "0351b9e3eea3e97e3830477c3d6d3961c4ed210d0de9cd59fa2675f5ffc94607"
},
"downloads": -1,
"filename": "revolving_asyncio-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fd2e11046fb800c9d60b06aefac4673f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 3545,
"upload_time": "2025-09-13T16:58:24",
"upload_time_iso_8601": "2025-09-13T16:58:24.211153Z",
"url": "https://files.pythonhosted.org/packages/61/fd/fce42c63ff370ec1a2947948c93393ea1aaf76c88345e5716bbb344f43e9/revolving_asyncio-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "725f3f10e4a28f6b23e3d7caa00070dfdd4467b946e16a495998c2450eaf40b5",
"md5": "58ea5c02120dffa838c732e9efd161d1",
"sha256": "3f6fd8bbc47a30ee862f8d8717c758c4045e708c266ff9d812257e81bd781203"
},
"downloads": -1,
"filename": "revolving_asyncio-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "58ea5c02120dffa838c732e9efd161d1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 4109,
"upload_time": "2025-09-13T16:58:24",
"upload_time_iso_8601": "2025-09-13T16:58:24.990664Z",
"url": "https://files.pythonhosted.org/packages/72/5f/3f10e4a28f6b23e3d7caa00070dfdd4467b946e16a495998c2450eaf40b5/revolving_asyncio-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-13 16:58:24",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "revolving-asyncio"
}