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

liteyuki.bot.lifespan

说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved

@Time : 2024/7/23 下午8:24 @Author : snowykami @Email : snowykami@outlook.com @File : lifespan.py @Software: PyCharm

class Lifespan

def __init__(self) -> None

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

源代码在GitHub上查看
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] = []
`,7),c={href:"https://docs.python.org/3/library/functions.html#staticmethod",target:"_blank",rel:"noopener noreferrer"},r=n("code",null,"@staticmethod",-1),d=s(`

async def run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None

说明: 并发运行异步函数

参数:

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

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

说明: 注册启动时的函数

参数:

返回: LIFESPAN_FUNC:

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

说明: 注册启动时的函数

参数:

返回: LIFESPAN_FUNC:

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

说明: 注册停止前的函数

参数:

返回: LIFESPAN_FUNC:

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

说明: 注册停止后的函数

参数:

返回: LIFESPAN_FUNC:

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

说明: 注册重启时的函数

参数:

返回: LIFESPAN_FUNC:

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

说明: 注册重启后的函数

参数:

返回: LIFESPAN_FUNC:

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

async def before_start(self) -> None

说明: 启动前

源代码在GitHub上查看
async def before_start(self) -> None:
    """
        启动前
        Returns:
        """
    logger.debug('Running before_start functions')
    await self.run_funcs(self._before_start_funcs)

async def after_start(self) -> None

说明: 启动后

源代码在GitHub上查看
async def after_start(self) -> None:
    """
        启动后
        Returns:
        """
    logger.debug('Running after_start functions')
    await self.run_funcs(self._after_start_funcs)

async def before_process_shutdown(self) -> None

说明: 停止前

源代码在GitHub上查看
async def before_process_shutdown(self) -> None:
    """
        停止前
        Returns:
        """
    logger.debug('Running before_shutdown functions')
    await self.run_funcs(self._before_process_shutdown_funcs)

async def after_shutdown(self) -> None

说明: 停止后

源代码在GitHub上查看
async def after_shutdown(self) -> None:
    """
        停止后
        Returns:
        """
    logger.debug('Running after_shutdown functions')
    await self.run_funcs(self._after_shutdown_funcs)

async def before_process_restart(self) -> None

说明: 重启前

源代码在GitHub上查看
async def before_process_restart(self) -> None:
    """
        重启前
        Returns:
        """
    logger.debug('Running before_restart functions')
    await self.run_funcs(self._before_process_restart_funcs)

async def after_restart(self) -> None

说明: 重启后

源代码在GitHub上查看
async def after_restart(self) -> None:
    """
        重启后
        Returns:

        """
    logger.debug('Running after_restart functions')
    await self.run_funcs(self._after_restart_funcs)
`,59);function k(f,m){const a=t("ExternalLinkIcon");return o(),p("div",null,[u,n("p",null,[n("a",c,[r,i(a)])]),d])}const v=e(l,[["render",k],["__file","lifespan.html.vue"]]),g=JSON.parse('{"path":"/dev/api/bot/lifespan.html","title":"liteyuki.bot.lifespan","lang":"zh-CN","frontmatter":{"title":"liteyuki.bot.lifespan","lastUpdated":false,"description":"liteyuki.bot.lifespan 说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 下午8:24 @Author : snowykami @Email : snowykami@outlook.com @File : lifespa...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/bot/lifespan.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/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":"liteyuki.bot.lifespan 说明: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 下午8:24 @Author : snowykami @Email : snowykami@outlook.com @File : lifespa..."}],["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.bot.lifespan\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class Lifespan","slug":"class-lifespan","link":"#class-lifespan","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":6}]},"readingTime":{"minutes":3.05,"words":916},"filePathRelative":"dev/api/bot/lifespan.md","localizedDate":"2024年8月19日","autoDesc":true}');export{v as comp,g as data};