import{_ as n,o as s,c as a,d as t}from"./app-CLi4lRj1.js";const e={},o=t(`

func is_coroutine_callable() -> bool

Description: 判断是否为协程可调用对象

Return: bool: 是否为协程可调用对象

Arguments:

Source code
def is_coroutine_callable(call: Callable[..., Any]) -> bool:
    """
    判断是否为协程可调用对象
    Args:
        call: 可调用对象
    Returns:
        bool: 是否为协程可调用对象
    """
    if inspect.isroutine(call):
        return inspect.iscoroutinefunction(call)
    if inspect.isclass(call):
        return False
    func_ = getattr(call, '__call__', None)
    return inspect.iscoroutinefunction(func_)

func run_coroutine()

Description: 运行协程

Arguments:

Source code
def run_coroutine(*coro: Coroutine):
    """
    运行协程
    Args:
        coro:

    Returns:

    """
    try:
        loop = asyncio.get_running_loop()
        if loop.is_running():
            for c in coro:
                asyncio.ensure_future(c)
        else:
            for c in coro:
                loop.run_until_complete(c)
    except RuntimeError:
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        loop.run_until_complete(asyncio.gather(*coro))
        loop.close()
    except Exception as e:
        logger.error(f'Exception occurred: {e}')

func run_coroutine_in_thread()

Description: 在新线程中运行协程

Arguments:

Source code
def run_coroutine_in_thread(*coro: Coroutine):
    """
    在新线程中运行协程
    Args:
        coro:

    Returns:

    """
    threading.Thread(target=run_coroutine, args=coro, daemon=True).start()

func path_to_module_name() -> str

Description: 转换路径为模块名

Return: str: 模块名

Arguments:

Source code
def path_to_module_name(path: Path) -> str:
    """
    转换路径为模块名
    Args:
        path: 路径a/b/c/d -> a.b.c.d
    Returns:
        str: 模块名
    """
    rel_path = path.resolve().relative_to(Path.cwd().resolve())
    if rel_path.stem == '__init__':
        return '.'.join(rel_path.parts[:-1])
    else:
        return '.'.join(rel_path.parts[:-1] + (rel_path.stem,))

func async_wrapper() -> Callable[..., Coroutine]

Description: 异步包装器

Return: Coroutine: Asynchronous Callable

Arguments:

Source code
def async_wrapper(func: Callable[..., Any]) -> Callable[..., Coroutine]:
    """
    异步包装器
    Args:
        func: Sync Callable
    Returns:
        Coroutine: Asynchronous Callable
    """

    async def wrapper(*args, **kwargs):
        return func(*args, **kwargs)
    wrapper.__signature__ = inspect.signature(func)
    return wrapper
`,28),p=[o];function c(l,i){return s(),a("div",null,p)}const r=n(e,[["render",c],["__file","utils.html.vue"]]),d=JSON.parse('{"path":"/en/api/utils.html","title":"liteyuki.utils","lang":"en-US","frontmatter":{"title":"liteyuki.utils","description":"func is_coroutine_callable() -> bool Description: 判断是否为协程可调用对象 Return: bool: 是否为协程可调用对象 Arguments: call: 可调用对象 Source code func run_coroutine() Description: 运行协程 Arguments: coro...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/api/utils.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/api/utils.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.utils"}],["meta",{"property":"og:description","content":"func is_coroutine_callable() -> bool Description: 判断是否为协程可调用对象 Return: bool: 是否为协程可调用对象 Arguments: call: 可调用对象 Source code func run_coroutine() Description: 运行协程 Arguments: coro..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.utils\\",\\"image\\":[\\"\\"],\\"dateModified\\":null,\\"author\\":[]}"]]},"headers":[{"level":3,"title":"func is_coroutine_callable() -> bool","slug":"func-is-coroutine-callable-bool","link":"#func-is-coroutine-callable-bool","children":[]},{"level":3,"title":"func run_coroutine()","slug":"func-run-coroutine","link":"#func-run-coroutine","children":[]},{"level":3,"title":"func run_coroutine_in_thread()","slug":"func-run-coroutine-in-thread","link":"#func-run-coroutine-in-thread","children":[]},{"level":3,"title":"func path_to_module_name() -> str","slug":"func-path-to-module-name-str","link":"#func-path-to-module-name-str","children":[]},{"level":3,"title":"func async_wrapper() -> Callable[..., Coroutine]","slug":"func-async-wrapper-callable-coroutine","link":"#func-async-wrapper-callable-coroutine","children":[]}],"git":{"createdTime":null,"updatedTime":null,"contributors":[]},"readingTime":{"minutes":1.19,"words":356},"filePathRelative":"en/api/utils.md","autoDesc":true}');export{r as comp,d as data};