mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-15 00:24:26 +08:00
129 lines
33 KiB
JavaScript
129 lines
33 KiB
JavaScript
|
import{_ as e,r as t,o,c as p,b as n,a as i,e as s}from"./app-BvUYPzLF.js";const c={},u=s(`<h1 id="liteyuki-bot-lifespan" tabindex="-1"><a class="header-anchor" href="#liteyuki-bot-lifespan"><span>liteyuki.bot.lifespan</span></a></h1><p><strong>Description</strong>: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p><p>@Time : 2024/7/23 下午8:24 @Author : snowykami @Email : snowykami@outlook.com @File : lifespan.py @Software: PyCharm</p><h3 id="class-lifespan" tabindex="-1"><a class="header-anchor" href="#class-lifespan"><span><em><strong>class</strong></em> <code>Lifespan</code></span></a></h3><h4 id="def-init-self-none" tabindex="-1"><a class="header-anchor" href="#def-init-self-none"><span><em><strong>def</strong></em> <code>__init__(self) -> None</code></span></a></h4><p><strong>Description</strong>: 轻雪生命周期管理,启动、停止、重启</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L27" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
轻雪生命周期管理,启动、停止、重启
|
|||
|
"""</span>
|
|||
|
self<span class="token punctuation">.</span>life_flag<span class="token punctuation">:</span> <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">0</span>
|
|||
|
self<span class="token punctuation">.</span>_before_start_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
|
|||
|
self<span class="token punctuation">.</span>_after_start_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
|
|||
|
self<span class="token punctuation">.</span>_before_process_shutdown_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
|
|||
|
self<span class="token punctuation">.</span>_after_shutdown_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
|
|||
|
self<span class="token punctuation">.</span>_before_process_restart_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
|
|||
|
self<span class="token punctuation">.</span>_after_restart_funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>LIFESPAN_FUNC<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details>`,7),l={href:"https://docs.python.org/3/library/functions.html#staticmethod",target:"_blank",rel:"noopener noreferrer"},r=n("code",null,"@staticmethod",-1),d=s(`<h4 id="async-def-run-funcs-funcs-list-async-lifespan-func-process-lifespan-func-args-kwargs-none" tabindex="-1"><a class="header-anchor" href="#async-def-run-funcs-funcs-list-async-lifespan-func-process-lifespan-func-args-kwargs-none"><span><em><strong>async def</strong></em> <code>run_funcs(funcs: list[ASYNC_LIFESPAN_FUNC | PROCESS_LIFESPAN_FUNC], *args, **kwargs) -> None</code></span></a></h4><p><strong>Description</strong>: 并发运行异步函数</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>funcs:</li></ul></blockquote><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L43" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token decorator annotation punctuation">@staticmethod</span>
|
|||
|
<span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">run_funcs</span><span class="token punctuation">(</span>funcs<span class="token punctuation">:</span> <span class="token builtin">list</span><span class="token punctuation">[</span>ASYNC_LIFESPAN_FUNC <span class="token operator">|</span> PROCESS_LIFESPAN_FUNC<span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
并发运行异步函数
|
|||
|
Args:
|
|||
|
funcs:
|
|||
|
Returns:
|
|||
|
"""</span>
|
|||
|
loop <span class="token operator">=</span> asyncio<span class="token punctuation">.</span>get_running_loop<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
tasks <span class="token operator">=</span> <span class="token punctuation">[</span>func<span class="token punctuation">(</span><span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span> <span class="token keyword">if</span> is_coroutine_callable<span class="token punctuation">(</span>func<span class="token punctuation">)</span> <span class="token keyword">else</span> async_wrapper<span class="token punctuation">(</span>func<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token operator">*</span>args<span class="token punctuation">,</span> <span class="token operator">**</span>kwargs<span class="token punctuation">)</span> <span class="token keyword">for</span> func <span class="token keyword">in</span> funcs<span class="token punctuation">]</span>
|
|||
|
<span class="token keyword">await</span> asyncio<span class="token punctuation">.</span>gather<span class="token punctuation">(</span><span class="token operator">*</span>tasks<span class="token punctuation">)</span>
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="def-on-before-start-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-start-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: 注册启动时的函数</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L54" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">on_before_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> LIFESPAN_FUNC<span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
注册启动时的函数
|
|||
|
Args:
|
|||
|
func:
|
|||
|
Returns:
|
|||
|
LIFESPAN_FUNC:
|
|||
|
"""</span>
|
|||
|
self<span class="token punctuation">.</span>_before_start_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> func
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="def-on-after-start-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-start-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_start(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: 注册启动时的函数</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L65" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">on_after_start</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> LIFESPAN_FUNC<span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
注册启动时的函数
|
|||
|
Args:
|
|||
|
func:
|
|||
|
Returns:
|
|||
|
LIFESPAN_FUNC:
|
|||
|
"""</span>
|
|||
|
self<span class="token punctuation">.</span>_after_start_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> func
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="def-on-before-process-shutdown-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-shutdown-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: 注册停止前的函数</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L76" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">on_before_process_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> LIFESPAN_FUNC<span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
注册停止前的函数
|
|||
|
Args:
|
|||
|
func:
|
|||
|
Returns:
|
|||
|
LIFESPAN_FUNC:
|
|||
|
"""</span>
|
|||
|
self<span class="token punctuation">.</span>_before_process_shutdown_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> func
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="def-on-after-shutdown-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-shutdown-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: 注册停止后的函数</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L87" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">on_after_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> LIFESPAN_FUNC<span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
注册停止后的函数
|
|||
|
Args:
|
|||
|
func:
|
|||
|
|
|||
|
Returns:
|
|||
|
LIFESPAN_FUNC:
|
|||
|
|
|||
|
"""</span>
|
|||
|
self<span class="token punctuation">.</span>_after_shutdown_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> func
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="def-on-before-process-restart-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-before-process-restart-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_before_process_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: 注册重启时的函数</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L100" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">on_before_process_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> LIFESPAN_FUNC<span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
注册重启时的函数
|
|||
|
Args:
|
|||
|
func:
|
|||
|
Returns:
|
|||
|
LIFESPAN_FUNC:
|
|||
|
"""</span>
|
|||
|
self<span class="token punctuation">.</span>_before_process_restart_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> func
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="def-on-after-restart-self-func-lifespan-func-lifespan-func" tabindex="-1"><a class="header-anchor" href="#def-on-after-restart-self-func-lifespan-func-lifespan-func"><span><em><strong>def</strong></em> <code>on_after_restart(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC</code></span></a></h4><p><strong>Description</strong>: 注册重启后的函数</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func:</li></ul></blockquote><p><strong>Return</strong>: LIFESPAN_FUNC:</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L111" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">def</span> <span class="token function">on_after_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> func<span class="token punctuation">:</span> LIFESPAN_FUNC<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> LIFESPAN_FUNC<span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
注册重启后的函数
|
|||
|
Args:
|
|||
|
func:
|
|||
|
Returns:
|
|||
|
LIFESPAN_FUNC:
|
|||
|
"""</span>
|
|||
|
self<span class="token punctuation">.</span>_after_restart_funcs<span class="token punctuation">.</span>append<span class="token punctuation">(</span>func<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> func
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="async-def-before-start-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-start-self-none"><span><em><strong>async def</strong></em> <code>before_start(self) -> None</code></span></a></h4><p><strong>Description</strong>: 启动前</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L122" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">before_start</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
启动前
|
|||
|
Returns:
|
|||
|
"""</span>
|
|||
|
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">'Running before_start functions'</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_start_funcs<span class="token punctuation">)</span>
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="async-def-after-start-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-start-self-none"><span><em><strong>async def</strong></em> <code>after_start(self) -> None</code></span></a></h4><p><strong>Description</strong>: 启动后</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L130" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">after_start</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
启动后
|
|||
|
Returns:
|
|||
|
"""</span>
|
|||
|
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">'Running after_start functions'</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_start_funcs<span class="token punctuation">)</span>
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="async-def-before-process-shutdown-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-process-shutdown-self-none"><span><em><strong>async def</strong></em> <code>before_process_shutdown(self) -> None</code></span></a></h4><p><strong>Description</strong>: 停止前</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L138" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">before_process_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
停止前
|
|||
|
Returns:
|
|||
|
"""</span>
|
|||
|
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">'Running before_shutdown functions'</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_process_shutdown_funcs<span class="token punctuation">)</span>
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="async-def-after-shutdown-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-shutdown-self-none"><span><em><strong>async def</strong></em> <code>after_shutdown(self) -> None</code></span></a></h4><p><strong>Description</strong>: 停止后</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L146" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">after_shutdown</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
停止后
|
|||
|
Returns:
|
|||
|
"""</span>
|
|||
|
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">'Running after_shutdown functions'</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_shutdown_funcs<span class="token punctuation">)</span>
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="async-def-before-process-restart-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-before-process-restart-self-none"><span><em><strong>async def</strong></em> <code>before_process_restart(self) -> None</code></span></a></h4><p><strong>Description</strong>: 重启前</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L154" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">before_process_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
重启前
|
|||
|
Returns:
|
|||
|
"""</span>
|
|||
|
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">'Running before_restart functions'</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_before_process_restart_funcs<span class="token punctuation">)</span>
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h4 id="async-def-after-restart-self-none" tabindex="-1"><a class="header-anchor" href="#async-def-after-restart-self-none"><span><em><strong>async def</strong></em> <code>after_restart(self) -> None</code></span></a></h4><p><strong>Description</strong>: 重启后</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/liteyuki/bot/lifespan.py#L162" target="_blank">View on GitHub</a></summary><div class="language-python line-numbers-mode" data-ext="py" data-title="py"><pre class="language-python"><code><span class="token keyword">async</span> <span class="token keyword">def</span> <span class="token function">after_restart</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
|||
|
<span class="token triple-quoted-string string">"""
|
|||
|
重启后
|
|||
|
Returns:
|
|||
|
|
|||
|
"""</span>
|
|||
|
logger<span class="token punctuation">.</span>debug<span class="token punctuation">(</span><span class="token string">'Running after_restart functions'</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">await</span> self<span class="token punctuation">.</span>run_funcs<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_after_restart_funcs<span class="token punctuation">)</span>
|
|||
|
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details>`,59);function k(f,m){const a=t("ExternalLinkIcon");return o(),p("div",null,[u,n("p",null,[n("a",l,[r,i(a)])]),d])}const v=e(c,[["render",k],["__file","lifespan.html.vue"]]),g=JSON.parse('{"path":"/en/dev/api/bot/lifespan.html","title":"liteyuki.bot.lifespan","lang":"en-US","frontmatter":{"title":"liteyuki.bot.lifespan","lastUpdated":false,"description":"liteyuki.bot.lifespan Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 下午8:24 @Author : snowykami @Email : snowykami@outlook.com @File ...","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":"liteyuki.bot.lifespan Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved @Time : 2024/7/23 下午8:24 @Author : snowykami @Email : snowykami@outlook.com @File ..."}],["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":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":2.82,"words":846},"filePathRelative":"en/dev/api/bot/lifespan.md","localizedDate":"August 21, 2024","autoDesc":true}');export{v as comp,g as data};
|