import{_ as s,c as i,o as a,a4 as n}from"./chunks/framework.BZiUP1E-.js";const u=JSON.parse('{"title":"liteyuki.bot.lifespan","description":"","frontmatter":{"title":"liteyuki.bot.lifespan"},"headers":[],"relativePath":"dev/api/bot/lifespan.md","filePath":"zh/dev/api/bot/lifespan.md","lastUpdated":null}'),t={name:"dev/api/bot/lifespan.md"},e=n(`

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

var SYNC_LIFESPAN_FUNC

var ASYNC_LIFESPAN_FUNC

var LIFESPAN_FUNC

var SYNC_PROCESS_LIFESPAN_FUNC

var ASYNC_PROCESS_LIFESPAN_FUNC

var PROCESS_LIFESPAN_FUNC

class Lifespan

func __init__(self) -> None

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

源代码在GitHub上查看
python
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[PROCESS_LIFESPAN_FUNC] = []
    self._after_shutdown_funcs: list[LIFESPAN_FUNC] = []
    self._before_process_restart_funcs: list[PROCESS_LIFESPAN_FUNC] = []
    self._after_restart_funcs: list[LIFESPAN_FUNC] = []

@staticmethod

async func run_funcs(funcs: Sequence[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None

说明: 并发运行异步函数

参数:

源代码在GitHub上查看
python
@staticmethod
async def run_funcs(funcs: Sequence[LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None:
    """
        并发运行异步函数
        Args:
            funcs ([\`Sequence\`](https%3A//docs.python.org/3/library/typing.html#typing.Sequence)[[\`ASYNC_LIFESPAN_FUNC\`](#var-lifespan-func) | [\`PROCESS_LIFESPAN_FUNC\`](#var-process-lifespan-func)]): 函数列表
        Returns:
        """
    tasks = [func(*args, **kwargs) if is_coroutine_callable(func) else async_wrapper(func)(*args, **kwargs) for func in funcs]
    await asyncio.gather(*tasks)

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

说明: 注册启动时的函数

参数:

返回: LIFESPAN_FUNC: 生命周期函数

源代码在GitHub上查看
python
def on_before_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册启动时的函数
        Args:
            func ([\`LIFESPAN_FUNC\`](#var-lifespan-func)): 生命周期函数
        Returns:
            [\`LIFESPAN_FUNC\`](#var-lifespan-func): 生命周期函数
        """
    self._before_start_funcs.append(func)
    return func

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

说明: 注册启动时的函数

参数:

返回: LIFESPAN_FUNC: 生命周期函数

源代码在GitHub上查看
python
def on_after_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册启动时的函数
        Args:
            func ([\`LIFESPAN_FUNC\`](#var-lifespan-func)): 生命周期函数
        Returns:
            [\`LIFESPAN_FUNC\`](#var-lifespan-func): 生命周期函数
        """
    self._after_start_funcs.append(func)
    return func

func on_before_process_shutdown(self, func: PROCESS_LIFESPAN_FUNC) -> PROCESS_LIFESPAN_FUNC

说明: 注册进程停止前的函数

参数:

返回: PROCESS_LIFESPAN_FUNC: 进程生命周期函数

源代码在GitHub上查看
python
def on_before_process_shutdown(self, func: PROCESS_LIFESPAN_FUNC) -> PROCESS_LIFESPAN_FUNC:
    """
        注册进程停止前的函数
        Args:
            func ([\`PROCESS_LIFESPAN_FUNC\`](#var-process-lifespan-func)): 进程生命周期函数
        Returns:
            [\`PROCESS_LIFESPAN_FUNC\`](#var-process-lifespan-func): 进程生命周期函数
        """
    self._before_process_shutdown_funcs.append(func)
    return func

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

说明: 注册停止后的函数

参数:

返回: LIFESPAN_FUNC: 生命周期函数

源代码在GitHub上查看
python
def on_after_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册停止后的函数
        Args:
            func ([\`LIFESPAN_FUNC\`](#var-lifespan-func)): 生命周期函数
        Returns:
            [\`LIFESPAN_FUNC\`](#var-lifespan-func): 生命周期函数
        """
    self._after_shutdown_funcs.append(func)
    return func

func on_before_process_restart(self, func: PROCESS_LIFESPAN_FUNC) -> PROCESS_LIFESPAN_FUNC

说明: 注册进程重启前的函数

参数:

返回: PROCESS_LIFESPAN_FUNC: 进程生命周期函数

源代码在GitHub上查看
python
def on_before_process_restart(self, func: PROCESS_LIFESPAN_FUNC) -> PROCESS_LIFESPAN_FUNC:
    """
        注册进程重启前的函数
        Args:
            func ([\`PROCESS_LIFESPAN_FUNC\`](#var-process-lifespan-func)): 进程生命周期函数
        Returns:
            [\`PROCESS_LIFESPAN_FUNC\`](#var-process-lifespan-func): 进程生命周期函数
        """
    self._before_process_restart_funcs.append(func)
    return func

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

说明: 注册重启后的函数

参数:

返回: LIFESPAN_FUNC: 生命周期函数

源代码在GitHub上查看
python
def on_after_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
    """
        注册重启后的函数
        Args:
            func ([\`LIFESPAN_FUNC\`](#var-lifespan-func)): 生命周期函数
        Returns:
            [\`LIFESPAN_FUNC\`](#var-lifespan-func): 生命周期函数
        """
    self._after_restart_funcs.append(func)
    return func

async func before_start(self) -> None

说明: 启动前钩子

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

async func after_start(self) -> None

说明: 启动后钩子

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

async func before_process_shutdown(self, *args, **kwargs) -> None

说明: 停止前钩子

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

async func after_shutdown(self) -> None

说明: 停止后钩子 未实现

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

async func before_process_restart(self, *args, **kwargs) -> None

说明: 重启前钩子

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

async func after_restart(self) -> None

说明: 重启后钩子 未实现

源代码在GitHub上查看
python
async def after_restart(self) -> None:
    """
        重启后钩子 未实现
        """
    logger.debug('Running after_restart functions')
    await self.run_funcs(self._after_restart_funcs)
`,79),l=[e];function p(h,k,r,o,c,d){return a(),i("div",null,l)}const E=s(t,[["render",p]]);export{u as __pageData,E as default};