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

class Lifespan

method __init__(self) -> None

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

Source code
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] = []

@staticmethod

async method run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None

Description: 并发运行异步函数

Arguments:

Source code
@staticmethod
async def run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None:
    """
        并发运行异步函数
        Args:
            funcs:
        Returns:
        """
    loop = asyncio.get_running_loop()
    tasks = [func(*args, **kwargs) if is_coroutine_callable(func) else async_wrapper(func)(*args, **kwargs) for func in funcs]
    await asyncio.gather(*tasks)

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

Description: 注册启动时的函数

Arguments:

Return: LIFESPAN_FUNC:

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

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

Description: 注册启动时的函数

Arguments:

Return: LIFESPAN_FUNC:

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

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

Description: 注册停止前的函数

Arguments:

Return: LIFESPAN_FUNC:

Source code
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

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

Description: 注册停止后的函数

Arguments:

Return: LIFESPAN_FUNC:

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

        Returns:
            LIFESPAN_FUNC:

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

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

Description: 注册重启时的函数

Arguments:

Return: LIFESPAN_FUNC:

Source code
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

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

Description: 注册重启后的函数

Arguments:

Return: LIFESPAN_FUNC:

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

async method before_start(self) -> None

Description: 启动前

Source code
async def before_start(self) -> None:
    """
        启动前
        Returns:
        """
    logger.debug('Running before_start functions')
    await self.run_funcs(self._before_start_funcs)

async method after_start(self) -> None

Description: 启动后

Source code
async def after_start(self) -> None:
    """
        启动后
        Returns:
        """
    logger.debug('Running after_start functions')
    await self.run_funcs(self._after_start_funcs)

async method before_process_shutdown(self) -> None

Description: 停止前

Source code
async def before_process_shutdown(self) -> None:
    """
        停止前
        Returns:
        """
    logger.debug('Running before_shutdown functions')
    await self.run_funcs(self._before_process_shutdown_funcs)

async method after_shutdown(self) -> None

Description: 停止后

Source code
async def after_shutdown(self) -> None:
    """
        停止后
        Returns:
        """
    logger.debug('Running after_shutdown functions')
    await self.run_funcs(self._after_shutdown_funcs)

async method before_process_restart(self) -> None

Description: 重启前

Source code
async def before_process_restart(self) -> None:
    """
        重启前
        Returns:
        """
    logger.debug('Running before_restart functions')
    await self.run_funcs(self._before_process_restart_funcs)

async method after_restart(self) -> None

Description: 重启后

Source code
async def after_restart(self) -> None:
    """
        重启后
        Returns:

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

var SYNC_LIFESPAN_FUNC = Callable[[], Any]

var ASYNC_LIFESPAN_FUNC = Callable[[], Awaitable[Any]]

var LIFESPAN_FUNC = SYNC_LIFESPAN_FUNC | ASYNC_LIFESPAN_FUNC

var SYNC_PROCESS_LIFESPAN_FUNC = Callable[[str], Any]

var ASYNC_PROCESS_LIFESPAN_FUNC = Callable[[str], Awaitable[Any]]

var PROCESS_LIFESPAN_FUNC = SYNC_PROCESS_LIFESPAN_FUNC | ASYNC_PROCESS_LIFESPAN_FUNC

`,76),l=[o];function c(p,i){return s(),a("div",null,l)}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","description":"class Lifespan method __init__(self) -> None Description: 轻雪生命周期管理,启动、停止、重启 Source code @staticmethod async method run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_F...","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":"class Lifespan method __init__(self) -> None Description: 轻雪生命周期管理,启动、停止、重启 Source code @staticmethod async method run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_F..."}],["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-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.bot.lifespan\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Lifespan","slug":"class-lifespan","link":"#class-lifespan","children":[]},{"level":3,"title":"method __init__(self) -> None","slug":"method-init-self-none","link":"#method-init-self-none","children":[]},{"level":3,"title":"@staticmethod","slug":"staticmethod","link":"#staticmethod","children":[]},{"level":3,"title":"async method run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC]) -> None","slug":"async-method-run-funcs-funcs-list-async-lifespan-func-process-lifespan-func-none","link":"#async-method-run-funcs-funcs-list-async-lifespan-func-process-lifespan-func-none","children":[]},{"level":3,"title":"method on_before_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"method-on-before-start-self-func-lifespan-func-lifespan-func","link":"#method-on-before-start-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"method on_after_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"method-on-after-start-self-func-lifespan-func-lifespan-func","link":"#method-on-after-start-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"method on_before_process_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"method-on-before-process-shutdown-self-func-lifespan-func-lifespan-func","link":"#method-on-before-process-shutdown-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"method on_after_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"method-on-after-shutdown-self-func-lifespan-func-lifespan-func","link":"#method-on-after-shutdown-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"method on_before_process_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"method-on-before-process-restart-self-func-lifespan-func-lifespan-func","link":"#method-on-before-process-restart-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"method on_after_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC","slug":"method-on-after-restart-self-func-lifespan-func-lifespan-func","link":"#method-on-after-restart-self-func-lifespan-func-lifespan-func","children":[]},{"level":3,"title":"async method before_start(self) -> None","slug":"async-method-before-start-self-none","link":"#async-method-before-start-self-none","children":[]},{"level":3,"title":"async method after_start(self) -> None","slug":"async-method-after-start-self-none","link":"#async-method-after-start-self-none","children":[]},{"level":3,"title":"async method before_process_shutdown(self) -> None","slug":"async-method-before-process-shutdown-self-none","link":"#async-method-before-process-shutdown-self-none","children":[]},{"level":3,"title":"async method after_shutdown(self) -> None","slug":"async-method-after-shutdown-self-none","link":"#async-method-after-shutdown-self-none","children":[]},{"level":3,"title":"async method before_process_restart(self) -> None","slug":"async-method-before-process-restart-self-none","link":"#async-method-before-process-restart-self-none","children":[]},{"level":3,"title":"async method after_restart(self) -> None","slug":"async-method-after-restart-self-none","link":"#async-method-after-restart-self-none","children":[]},{"level":3,"title":"var SYNC_LIFESPAN_FUNC = Callable[[], Any]","slug":"var-sync-lifespan-func-callable-any","link":"#var-sync-lifespan-func-callable-any","children":[]},{"level":3,"title":"var ASYNC_LIFESPAN_FUNC = Callable[[], Awaitable[Any]]","slug":"var-async-lifespan-func-callable-awaitable-any","link":"#var-async-lifespan-func-callable-awaitable-any","children":[]},{"level":3,"title":"var LIFESPAN_FUNC = SYNC_LIFESPAN_FUNC | ASYNC_LIFESPAN_FUNC","slug":"var-lifespan-func-sync-lifespan-func-async-lifespan-func","link":"#var-lifespan-func-sync-lifespan-func-async-lifespan-func","children":[]},{"level":3,"title":"var SYNC_PROCESS_LIFESPAN_FUNC = Callable[[str], Any]","slug":"var-sync-process-lifespan-func-callable-str-any","link":"#var-sync-process-lifespan-func-callable-str-any","children":[]},{"level":3,"title":"var ASYNC_PROCESS_LIFESPAN_FUNC = Callable[[str], Awaitable[Any]]","slug":"var-async-process-lifespan-func-callable-str-awaitable-any","link":"#var-async-process-lifespan-func-callable-str-awaitable-any","children":[]},{"level":3,"title":"var PROCESS_LIFESPAN_FUNC = SYNC_PROCESS_LIFESPAN_FUNC | ASYNC_PROCESS_LIFESPAN_FUNC","slug":"var-process-lifespan-func-sync-process-lifespan-func-async-process-lifespan-func","link":"#var-process-lifespan-func-sync-process-lifespan-func-async-process-lifespan-func","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":2.29,"words":687},"filePathRelative":"en/dev/api/bot/lifespan.md","localizedDate":"August 21, 2024","autoDesc":true}');export{r as comp,d as data};