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

def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None

运行函数

Args:

funcs:

Returns:

源代码
@staticmethod
def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None:
    """
        运行函数
        Args:
            funcs:
        Returns:
        """
    try:
        loop = asyncio.get_event_loop()
    except RuntimeError:
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
    tasks = []
    for func in funcs:
        if is_coroutine_callable(func):
            tasks.append(func(*args, **kwargs))
        else:
            tasks.append(async_wrapper(func)(*args, **kwargs))
    loop.run_until_complete(asyncio.gather(*tasks))

class Lifespan

def __init__(self) -> None

 轻雪生命周期管理,启动、停止、重启

源代码
def __init__(self) -> None:
    """
        轻雪生命周期管理,启动、停止、重启
        """
    self.life_flag: int = 0
    self._before_start_funcs: list[LIFESPAN_FUNC] = []
    self._after_start_funcs: list[LIFESPAN_FUNC] = []
    self._before_process_shutdown_funcs: list[LIFESPAN_FUNC] = []
    self._after_shutdown_funcs: list[LIFESPAN_FUNC] = []
    self._before_process_restart_funcs: list[LIFESPAN_FUNC] = []
    self._after_restart_funcs: list[LIFESPAN_FUNC] = []
    self._after_nonebot_init_funcs: list[LIFESPAN_FUNC] = []

@staticmethod

def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None

 运行函数

Args:

funcs:

Returns:

源代码
@staticmethod
def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None:
    """
        运行函数
        Args:
            funcs:
        Returns:
        """
    try:
        loop = asyncio.get_event_loop()
    except RuntimeError:
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
    tasks = []
    for func in funcs:
        if is_coroutine_callable(func):
            tasks.append(func(*args, **kwargs))
        else:
            tasks.append(async_wrapper(func)(*args, **kwargs))
    loop.run_until_complete(asyncio.gather(*tasks))

def on_before_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC

 注册启动时的函数

Args:

func:

Returns:

LIFESPAN_FUNC:
源代码
def on_before_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册启动时的函数
        Args:
            func:
        Returns:
            LIFESPAN_FUNC:
        """
    self._before_start_funcs.append(func)
    return func

def on_after_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC

 注册启动时的函数

Args:

func:

Returns:

LIFESPAN_FUNC:
源代码
def on_after_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册启动时的函数
        Args:
            func:
        Returns:
            LIFESPAN_FUNC:
        """
    self._after_start_funcs.append(func)
    return func

def on_before_process_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC

 注册停止前的函数

Args:

func:

Returns:

LIFESPAN_FUNC:
源代码
def on_before_process_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册停止前的函数
        Args:
            func:
        Returns:
            LIFESPAN_FUNC:
        """
    self._before_process_shutdown_funcs.append(func)
    return func

def on_after_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC

 注册停止后的函数

Args:

func:

Returns:

LIFESPAN_FUNC:
源代码
def on_after_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册停止后的函数
        Args:
            func:

        Returns:
            LIFESPAN_FUNC:

        """
    self._after_shutdown_funcs.append(func)
    return func

def on_before_process_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC

 注册重启时的函数

Args:

func:

Returns:

LIFESPAN_FUNC:
源代码
def on_before_process_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册重启时的函数
        Args:
            func:
        Returns:
            LIFESPAN_FUNC:
        """
    self._before_process_restart_funcs.append(func)
    return func

def on_after_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC

 注册重启后的函数

Args:

func:

Returns:

LIFESPAN_FUNC:
源代码
def on_after_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册重启后的函数
        Args:
            func:
        Returns:
            LIFESPAN_FUNC:
        """
    self._after_restart_funcs.append(func)
    return func

def on_after_nonebot_init(self, func: Any) -> None

 注册 NoneBot 初始化后的函数

Args:

func:

Returns:

源代码
def on_after_nonebot_init(self, func):
    """
        注册 NoneBot 初始化后的函数
        Args:
            func:

        Returns:

        """
    self._after_nonebot_init_funcs.append(func)
    return func

def before_start(self) -> None

 启动前

Returns:

源代码
def before_start(self) -> None:
    """
        启动前
        Returns:
        """
    logger.debug('Running before_start functions')
    self.run_funcs(self._before_start_funcs)

def after_start(self) -> None

 启动后

Returns:

源代码
def after_start(self) -> None:
    """
        启动后
        Returns:
        """
    logger.debug('Running after_start functions')
    self.run_funcs(self._after_start_funcs)

def before_process_shutdown(self) -> None

 停止前

Returns:

源代码
def before_process_shutdown(self) -> None:
    """
        停止前
        Returns:
        """
    logger.debug('Running before_shutdown functions')
    self.run_funcs(self._before_process_shutdown_funcs)

def after_shutdown(self) -> None

 停止后

Returns:

源代码
def after_shutdown(self) -> None:
    """
        停止后
        Returns:
        """
    logger.debug('Running after_shutdown functions')
    self.run_funcs(self._after_shutdown_funcs)

def before_process_restart(self) -> None

 重启前

Returns:

源代码
def before_process_restart(self) -> None:
    """
        重启前
        Returns:
        """
    logger.debug('Running before_restart functions')
    self.run_funcs(self._before_process_restart_funcs)

def after_restart(self) -> None

 重启后

Returns:

源代码
def after_restart(self) -> None:
    """
        重启后
        Returns:

        """
    logger.debug('Running after_restart functions')
    self.run_funcs(self._after_restart_funcs)

var tasks = []

var loop = asyncio.get_event_loop()

var loop = asyncio.new_event_loop()

`,92),p=[o];function c(l,i){return s(),a("div",null,p)}const r=n(t,[["render",c],["__file","lifespan.html.vue"]]),d=JSON.parse('{"path":"/en/dev/api/bot/lifespan.html","title":"liteyuki.bot.lifespan","lang":"en-US","frontmatter":{"title":"liteyuki.bot.lifespan","order":1,"icon":"laptop-code","category":"API","description":"def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None 运行函数 Args: Returns: 源代码 class Lifespan def __init__(self) -> None 轻雪生命周期管理,启动、停止、重启 源代码 @staticmethod d...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/bot/lifespan.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/bot/lifespan.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.bot.lifespan"}],["meta",{"property":"og:description","content":"def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None 运行函数 Args: Returns: 源代码 class Lifespan def __init__(self) -> None 轻雪生命周期管理,启动、停止、重启 源代码 @staticmethod d..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-21T09:59:21.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-21T09:59:21.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.bot.lifespan\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-21T09:59:21.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None","slug":"def-run-funcs-funcs-list-lifespan-func-process-lifespan-func-none","link":"#def-run-funcs-funcs-list-lifespan-func-process-lifespan-func-none","children":[]},{"level":3,"title":"class Lifespan","slug":"class-lifespan","link":"#class-lifespan","children":[]},{"level":3,"title":"def __init__(self) -> None","slug":"def-init-self-none","link":"#def-init-self-none","children":[]},{"level":3,"title":"@staticmethod","slug":"staticmethod","link":"#staticmethod","children":[]},{"level":3,"title":"def run_funcs(funcs: list[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None","slug":"def-run-funcs-funcs-list-lifespan-func-process-lifespan-func-none-1","link":"#def-run-funcs-funcs-list-lifespan-func-process-lifespan-func-none-1","children":[]},{"level":3,"title":"def on_before_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"def-on-before-start-self-func-lifespan-func-lifespan-func","link":"#def-on-before-start-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"def on_after_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"def-on-after-start-self-func-lifespan-func-lifespan-func","link":"#def-on-after-start-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"def on_before_process_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"def-on-before-process-shutdown-self-func-lifespan-func-lifespan-func","link":"#def-on-before-process-shutdown-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"def on_after_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"def-on-after-shutdown-self-func-lifespan-func-lifespan-func","link":"#def-on-after-shutdown-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"def on_before_process_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"def-on-before-process-restart-self-func-lifespan-func-lifespan-func","link":"#def-on-before-process-restart-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"def on_after_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"def-on-after-restart-self-func-lifespan-func-lifespan-func","link":"#def-on-after-restart-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"def on_after_nonebot_init(self, func: Any) -> None","slug":"def-on-after-nonebot-init-self-func-any-none","link":"#def-on-after-nonebot-init-self-func-any-none","children":[]},{"level":3,"title":"def before_start(self) -> None","slug":"def-before-start-self-none","link":"#def-before-start-self-none","children":[]},{"level":3,"title":"def after_start(self) -> None","slug":"def-after-start-self-none","link":"#def-after-start-self-none","children":[]},{"level":3,"title":"def before_process_shutdown(self) -> None","slug":"def-before-process-shutdown-self-none","link":"#def-before-process-shutdown-self-none","children":[]},{"level":3,"title":"def after_shutdown(self) -> None","slug":"def-after-shutdown-self-none","link":"#def-after-shutdown-self-none","children":[]},{"level":3,"title":"def before_process_restart(self) -> None","slug":"def-before-process-restart-self-none","link":"#def-before-process-restart-self-none","children":[]},{"level":3,"title":"def after_restart(self) -> None","slug":"def-after-restart-self-none","link":"#def-after-restart-self-none","children":[]},{"level":3,"title":"var tasks = []","slug":"var-tasks","link":"#var-tasks","children":[]},{"level":3,"title":"var loop = asyncio.get_event_loop()","slug":"var-loop-asyncio-get-event-loop","link":"#var-loop-asyncio-get-event-loop","children":[]},{"level":3,"title":"var loop = asyncio.new_event_loop()","slug":"var-loop-asyncio-new-event-loop","link":"#var-loop-asyncio-new-event-loop","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724234361000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":1}]},"readingTime":{"minutes":2.58,"words":773},"filePathRelative":"en/dev/api/bot/lifespan.md","localizedDate":"August 21, 2024","autoDesc":true}');export{r as comp,d as data};