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

liteyuki.utils

说明: 一些常用的工具类,部分来源于 nonebot 并遵循其许可进行修改

def is_coroutine_callable(call: Callable[..., Any]) -> bool

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

参数:

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

源代码在GitHub上查看
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_)

def run_coroutine(*coro: Coroutine)

说明: 运行协程

参数:

源代码在GitHub上查看
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}')

def run_coroutine_in_thread(*coro: Coroutine)

说明: 在新线程中运行协程

参数:

源代码在GitHub上查看
def run_coroutine_in_thread(*coro: Coroutine):
    """
    在新线程中运行协程
    Args:
        coro:

    Returns:

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

def path_to_module_name(path: Path) -> str

说明: 转换路径为模块名

参数:

返回: str: 模块名

源代码在GitHub上查看
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,))

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

说明: 异步包装器

参数:

返回: Coroutine: Asynchronous Callable

源代码在GitHub上查看
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
`,30),p=[o];function l(i,c){return s(),a("div",null,p)}const r=n(e,[["render",l],["__file","utils.html.vue"]]),d=JSON.parse('{"path":"/dev/api/utils.html","title":"liteyuki.utils","lang":"zh-CN","frontmatter":{"title":"liteyuki.utils","lastUpdated":false,"description":"liteyuki.utils 说明: 一些常用的工具类,部分来源于 nonebot 并遵循其许可进行修改 def is_coroutine_callable(call: Callable[..., Any]) -> bool 说明: 判断是否为协程可调用对象 参数: call: 可调用对象 返回: bool: 是否为协程可调用对象 源代码 或 在Git...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/utils.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/utils.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.utils"}],["meta",{"property":"og:description","content":"liteyuki.utils 说明: 一些常用的工具类,部分来源于 nonebot 并遵循其许可进行修改 def is_coroutine_callable(call: Callable[..., Any]) -> bool 说明: 判断是否为协程可调用对象 参数: call: 可调用对象 返回: bool: 是否为协程可调用对象 源代码 或 在Git..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:locale:alternate","content":"en-US"}],["meta",{"property":"og:updated_time","content":"2024-08-29T06:19:39.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-29T06:19:39.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.utils\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def is_coroutine_callable(call: Callable[..., Any]) -> bool","slug":"def-is-coroutine-callable-call-callable-any-bool","link":"#def-is-coroutine-callable-call-callable-any-bool","children":[]},{"level":3,"title":"def run_coroutine(*coro: Coroutine)","slug":"def-run-coroutine-coro-coroutine","link":"#def-run-coroutine-coro-coroutine","children":[]},{"level":3,"title":"def run_coroutine_in_thread(*coro: Coroutine)","slug":"def-run-coroutine-in-thread-coro-coroutine","link":"#def-run-coroutine-in-thread-coro-coroutine","children":[]},{"level":3,"title":"def path_to_module_name(path: Path) -> str","slug":"def-path-to-module-name-path-path-str","link":"#def-path-to-module-name-path-path-str","children":[]},{"level":3,"title":"def async_wrapper(func: Callable[..., Any]) -> Callable[..., Coroutine]","slug":"def-async-wrapper-func-callable-any-callable-coroutine","link":"#def-async-wrapper-func-callable-any-callable-coroutine","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":5}]},"readingTime":{"minutes":1.62,"words":487},"filePathRelative":"dev/api/utils.md","localizedDate":"2024年8月19日","autoDesc":true}');export{r as comp,d as data};