1
0
forked from bot/app

⬇️ 更新文档样式

This commit is contained in:
2024-08-29 14:19:39 +08:00
parent 3a3ef4d6ae
commit f12b6854b7
70 changed files with 3676 additions and 3257 deletions

View File

@ -1,24 +1,20 @@
---
title: liteyuki.utils
order: 1
icon: laptop-code
category: API
---
### *func* `is_coroutine_callable() -> bool`
### ***def*** `is_coroutine_callable(call: Callable[..., Any]) -> bool`
判断是否为协程可调用对象
Args:
**Description**: 判断是否为协程可调用对象
call: 可调用对象
**Arguments**:
> - call: 可调用对象
Returns:
**Return**: bool: 是否为协程可调用对象
bool: 是否为协程可调用对象
<details>
<summary>源代码</summary>
<summary> <b>Source code</b> </summary>
```python
def is_coroutine_callable(call: Callable[..., Any]) -> bool:
@ -38,20 +34,18 @@ def is_coroutine_callable(call: Callable[..., Any]) -> bool:
```
</details>
### ***def*** `run_coroutine() -> None`
运行协程
Args:
coro:
### *func* `run_coroutine()`
Returns:
**Description**: 运行协程
**Arguments**:
> - coro:
<details>
<summary>源代码</summary>
<summary> <b>Source code</b> </summary>
```python
def run_coroutine(*coro: Coroutine):
@ -81,20 +75,47 @@ def run_coroutine(*coro: Coroutine):
```
</details>
### ***def*** `path_to_module_name(path: Path) -> str`
### *func* `run_coroutine_in_thread()`
转换路径为模块名
Args:
path: 路径a/b/c/d -> a.b.c.d
**Description**: 在新线程中运行协程
Returns:
**Arguments**:
> - coro:
str: 模块名
<details>
<summary>源代码</summary>
<summary> <b>Source code</b> </summary>
```python
def run_coroutine_in_thread(*coro: Coroutine):
"""
在新线程中运行协程
Args:
coro:
Returns:
"""
threading.Thread(target=run_coroutine, args=coro, daemon=True).start()
```
</details>
### *func* `path_to_module_name() -> str`
**Description**: 转换路径为模块名
**Arguments**:
> - path: 路径a/b/c/d -> a.b.c.d
**Return**: str: 模块名
<details>
<summary> <b>Source code</b> </summary>
```python
def path_to_module_name(path: Path) -> str:
@ -113,20 +134,20 @@ def path_to_module_name(path: Path) -> str:
```
</details>
### ***def*** `async_wrapper(func: Callable[..., Any]) -> Callable[..., Coroutine]`
### *func* `async_wrapper() -> Callable[..., Coroutine]`
异步包装器
Args:
func: Sync Callable
**Description**: 异步包装器
Returns:
**Arguments**:
> - func: Sync Callable
**Return**: Coroutine: Asynchronous Callable
Coroutine: Asynchronous Callable
<details>
<summary>源代码</summary>
<summary> <b>Source code</b> </summary>
```python
def async_wrapper(func: Callable[..., Any]) -> Callable[..., Coroutine]:
@ -145,36 +166,3 @@ def async_wrapper(func: Callable[..., Any]) -> Callable[..., Coroutine]:
```
</details>
### ***async def*** `wrapper() -> None`
<details>
<summary>源代码</summary>
```python
async def wrapper(*args, **kwargs):
return func(*args, **kwargs)
```
</details>
### ***var*** `IS_MAIN_PROCESS = multiprocessing.current_process().name == 'MainProcess'`
### ***var*** `func_ = getattr(call, '__call__', None)`
### ***var*** `rel_path = path.resolve().relative_to(Path.cwd().resolve())`
### ***var*** `loop = asyncio.get_event_loop()`
### ***var*** `loop = asyncio.new_event_loop()`