forked from bot/app
102 lines
34 KiB
JavaScript
102 lines
34 KiB
JavaScript
import{_ as n,o as s,c as a,e}from"./app-BrSLFMno.js";const t={},p=e(`<h3 id="class-channeldeliver" tabindex="-1"><a class="header-anchor" href="#class-channeldeliver"><span><strong>class</strong> <code>ChannelDeliver</code></span></a></h3><h3 id="method-init-self-active-channel-any-passive-channel-any-channel-deliver-active-channel-channel-any-channel-deliver-passive-channel-tuple-str-dict-publish-channel-tuple-str-any" tabindex="-1"><a class="header-anchor" href="#method-init-self-active-channel-any-passive-channel-any-channel-deliver-active-channel-channel-any-channel-deliver-passive-channel-tuple-str-dict-publish-channel-tuple-str-any"><span><em>method</em> <code>__init__(self, active: Channel[Any], passive: Channel[Any], channel_deliver_active: Channel[Channel[Any]], channel_deliver_passive: Channel[tuple[str, dict]], publish: Channel[tuple[str, Any]])</code></span></a></h3><details><summary><b>Source code</b></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> active<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">,</span> passive<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">,</span> channel_deliver_active<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span>Channel<span class="token punctuation">[</span>Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">,</span> channel_deliver_passive<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span><span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">,</span> publish<span class="token punctuation">:</span> Channel<span class="token punctuation">[</span><span class="token builtin">tuple</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> Any<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
self<span class="token punctuation">.</span>active <span class="token operator">=</span> active
|
||
self<span class="token punctuation">.</span>passive <span class="token operator">=</span> passive
|
||
self<span class="token punctuation">.</span>channel_deliver_active <span class="token operator">=</span> channel_deliver_active
|
||
self<span class="token punctuation">.</span>channel_deliver_passive <span class="token operator">=</span> channel_deliver_passive
|
||
self<span class="token punctuation">.</span>publish <span class="token operator">=</span> publish
|
||
</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></div></details><h3 id="class-processmanager" tabindex="-1"><a class="header-anchor" href="#class-processmanager"><span><strong>class</strong> <code>ProcessManager</code></span></a></h3><h3 id="method-init-self-lifespan-lifespan" tabindex="-1"><a class="header-anchor" href="#method-init-self-lifespan-lifespan"><span><em>method</em> <code>__init__(self, lifespan: Lifespan)</code></span></a></h3><details><summary><b>Source code</b></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> lifespan<span class="token punctuation">:</span> <span class="token string">'Lifespan'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
self<span class="token punctuation">.</span>lifespan <span class="token operator">=</span> lifespan
|
||
self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span> <span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> <span class="token builtin">tuple</span><span class="token punctuation">[</span>Callable<span class="token punctuation">,</span> <span class="token builtin">tuple</span><span class="token punctuation">,</span> <span class="token builtin">dict</span><span class="token punctuation">]</span><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>processes<span class="token punctuation">:</span> <span class="token builtin">dict</span><span class="token punctuation">[</span><span class="token builtin">str</span><span class="token punctuation">,</span> Process<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></div></details><h3 id="async-method-run-process-self-name-str" tabindex="-1"><a class="header-anchor" href="#async-method-run-process-self-name-str"><span><em>async method</em> <code>_run_process(self, name: str)</code></span></a></h3><p><strong>Description</strong>: 开启后自动监控进程,并添加到进程字典中,会阻塞,请创建task</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name:</li></ul></blockquote><details><summary><b>Source code</b></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">_run_process</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
<span class="token triple-quoted-string string">"""
|
||
开启后自动监控进程,并添加到进程字典中,会阻塞,请创建task
|
||
Args:
|
||
name:
|
||
Returns:
|
||
"""</span>
|
||
<span class="token keyword">if</span> name <span class="token keyword">not</span> <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span>
|
||
<span class="token keyword">raise</span> KeyError<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f'Process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> not found.'</span></span><span class="token punctuation">)</span>
|
||
chan_active <span class="token operator">=</span> get_channel<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">-active'</span></span><span class="token punctuation">)</span>
|
||
|
||
<span class="token keyword">def</span> <span class="token function">_start_process</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
process <span class="token operator">=</span> Process<span class="token punctuation">(</span>target<span class="token operator">=</span>self<span class="token punctuation">.</span>targets<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> args<span class="token operator">=</span>self<span class="token punctuation">.</span>targets<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> kwargs<span class="token operator">=</span>self<span class="token punctuation">.</span>targets<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> daemon<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span>
|
||
self<span class="token punctuation">.</span>processes<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> process
|
||
process<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
_start_process<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
|
||
data <span class="token operator">=</span> <span class="token keyword">await</span> chan_active<span class="token punctuation">.</span>async_receive<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
<span class="token keyword">if</span> data <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">:</span>
|
||
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f'Stopping process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">'</span></span><span class="token punctuation">)</span>
|
||
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>before_process_shutdown<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
self<span class="token punctuation">.</span>terminate<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
|
||
<span class="token keyword">break</span>
|
||
<span class="token keyword">elif</span> data <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">:</span>
|
||
logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f'Restarting process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">'</span></span><span class="token punctuation">)</span>
|
||
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>before_process_shutdown<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
<span class="token keyword">await</span> self<span class="token punctuation">.</span>lifespan<span class="token punctuation">.</span>before_process_restart<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
self<span class="token punctuation">.</span>terminate<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
|
||
_start_process<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
<span class="token keyword">continue</span>
|
||
<span class="token keyword">else</span><span class="token punctuation">:</span>
|
||
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string">'Unknown data received, ignored.'</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 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 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><h3 id="async-method-start-all-self" tabindex="-1"><a class="header-anchor" href="#async-method-start-all-self"><span><em>async method</em> <code>start_all(self)</code></span></a></h3><p><strong>Description</strong>: 对外启动方法,启动所有进程,创建asyncio task</p><details><summary><b>Source code</b></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">start_all</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
<span class="token triple-quoted-string string">"""
|
||
对外启动方法,启动所有进程,创建asyncio task
|
||
"""</span>
|
||
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>chan<span class="token punctuation">.</span>start_receive_loop<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> chan <span class="token keyword">in</span> get_channels<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>values<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span>
|
||
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>sm<span class="token punctuation">.</span>start_receive_loop<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> sm <span class="token keyword">in</span> <span class="token punctuation">[</span>shared_memory<span class="token punctuation">]</span><span class="token punctuation">]</span>
|
||
<span class="token punctuation">[</span>asyncio<span class="token punctuation">.</span>create_task<span class="token punctuation">(</span>self<span class="token punctuation">.</span>_run_process<span class="token punctuation">(</span>name<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">for</span> name <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<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><h3 id="method-add-target-self-name-str-target-target-func-args-tuple-kwargs-none" tabindex="-1"><a class="header-anchor" href="#method-add-target-self-name-str-target-target-func-args-tuple-kwargs-none"><span><em>method</em> <code>add_target(self, name: str, target: TARGET_FUNC, args: tuple = (), kwargs = None)</code></span></a></h3><p><strong>Description</strong>: 添加进程</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name: 进程名,用于获取和唯一标识</li><li>target: 进程函数</li><li>args: 进程函数参数</li><li>kwargs: 进程函数关键字参数,通常会默认传入chan_active和chan_passive</li></ul></blockquote><details><summary><b>Source code</b></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">add_target</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">,</span> target<span class="token punctuation">:</span> TARGET_FUNC<span class="token punctuation">,</span> args<span class="token punctuation">:</span> <span class="token builtin">tuple</span><span class="token operator">=</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> kwargs<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
<span class="token triple-quoted-string string">"""
|
||
添加进程
|
||
Args:
|
||
name: 进程名,用于获取和唯一标识
|
||
target: 进程函数
|
||
args: 进程函数参数
|
||
kwargs: 进程函数关键字参数,通常会默认传入chan_active和chan_passive
|
||
"""</span>
|
||
<span class="token keyword">if</span> kwargs <span class="token keyword">is</span> <span class="token boolean">None</span><span class="token punctuation">:</span>
|
||
kwargs <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
|
||
chan_active<span class="token punctuation">:</span> Channel <span class="token operator">=</span> Channel<span class="token punctuation">(</span>name<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">-active'</span></span><span class="token punctuation">)</span>
|
||
chan_passive<span class="token punctuation">:</span> Channel <span class="token operator">=</span> Channel<span class="token punctuation">(</span>name<span class="token operator">=</span><span class="token string-interpolation"><span class="token string">f'</span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string">-passive'</span></span><span class="token punctuation">)</span>
|
||
channel_deliver <span class="token operator">=</span> ChannelDeliver<span class="token punctuation">(</span>active<span class="token operator">=</span>chan_active<span class="token punctuation">,</span> passive<span class="token operator">=</span>chan_passive<span class="token punctuation">,</span> channel_deliver_active<span class="token operator">=</span>channel_deliver_active_channel<span class="token punctuation">,</span> channel_deliver_passive<span class="token operator">=</span>channel_deliver_passive_channel<span class="token punctuation">,</span> publish<span class="token operator">=</span>publish_channel<span class="token punctuation">)</span>
|
||
self<span class="token punctuation">.</span>targets<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">(</span>_delivery_channel_wrapper<span class="token punctuation">,</span> <span class="token punctuation">(</span>target<span class="token punctuation">,</span> channel_deliver<span class="token punctuation">,</span> shared_memory<span class="token punctuation">,</span> <span class="token operator">*</span>args<span class="token punctuation">)</span><span class="token punctuation">,</span> kwargs<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 class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></details><h3 id="method-join-all-self" tabindex="-1"><a class="header-anchor" href="#method-join-all-self"><span><em>method</em> <code>join_all(self)</code></span></a></h3><details><summary><b>Source code</b></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">join_all</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
<span class="token keyword">for</span> <span class="token punctuation">(</span>name<span class="token punctuation">,</span> process<span class="token punctuation">)</span> <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span>
|
||
process<span class="token punctuation">.</span>join<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></div></details><h3 id="method-terminate-self-name-str" tabindex="-1"><a class="header-anchor" href="#method-terminate-self-name-str"><span><em>method</em> <code>terminate(self, name: str)</code></span></a></h3><p><strong>Description</strong>: 终止进程并从进程字典中删除</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name:</li></ul></blockquote><details><summary><b>Source code</b></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">terminate</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
<span class="token triple-quoted-string string">"""
|
||
终止进程并从进程字典中删除
|
||
Args:
|
||
name:
|
||
|
||
Returns:
|
||
|
||
"""</span>
|
||
<span class="token keyword">if</span> name <span class="token keyword">not</span> <span class="token keyword">in</span> self<span class="token punctuation">.</span>processes<span class="token punctuation">:</span>
|
||
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f'Process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> not found.'</span></span><span class="token punctuation">)</span>
|
||
<span class="token keyword">return</span>
|
||
process <span class="token operator">=</span> self<span class="token punctuation">.</span>processes<span class="token punctuation">[</span>name<span class="token punctuation">]</span>
|
||
process<span class="token punctuation">.</span>terminate<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
process<span class="token punctuation">.</span>join<span class="token punctuation">(</span>TIMEOUT<span class="token punctuation">)</span>
|
||
<span class="token keyword">if</span> process<span class="token punctuation">.</span>is_alive<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
process<span class="token punctuation">.</span>kill<span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||
logger<span class="token punctuation">.</span>success<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f'Process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> terminated.'</span></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 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><h3 id="method-terminate-all-self" tabindex="-1"><a class="header-anchor" href="#method-terminate-all-self"><span><em>method</em> <code>terminate_all(self)</code></span></a></h3><details><summary><b>Source code</b></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">terminate_all</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
|
||
<span class="token keyword">for</span> name <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span>
|
||
self<span class="token punctuation">.</span>terminate<span class="token punctuation">(</span>name<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></div></details><h3 id="method-is-process-alive-self-name-str-bool" tabindex="-1"><a class="header-anchor" href="#method-is-process-alive-self-name-str-bool"><span><em>method</em> <code>is_process_alive(self, name: str) -> bool</code></span></a></h3><p><strong>Description</strong>: 检查进程是否存活</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>name:</li></ul></blockquote><details><summary><b>Source code</b></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">is_process_alive</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token builtin">bool</span><span class="token punctuation">:</span>
|
||
<span class="token triple-quoted-string string">"""
|
||
检查进程是否存活
|
||
Args:
|
||
name:
|
||
|
||
Returns:
|
||
|
||
"""</span>
|
||
<span class="token keyword">if</span> name <span class="token keyword">not</span> <span class="token keyword">in</span> self<span class="token punctuation">.</span>targets<span class="token punctuation">:</span>
|
||
logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f'Process </span><span class="token interpolation"><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span><span class="token string"> not found.'</span></span><span class="token punctuation">)</span>
|
||
<span class="token keyword">return</span> self<span class="token punctuation">.</span>processes<span class="token punctuation">[</span>name<span class="token punctuation">]</span><span class="token punctuation">.</span>is_alive<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 class="line-number"></div></div></div></details><h3 id="var-target-func-callable-any" tabindex="-1"><a class="header-anchor" href="#var-target-func-callable-any"><span><em><strong>var</strong></em> <code>TARGET_FUNC = Callable[..., Any]</code></span></a></h3><ul><li><strong>Type</strong>: <code>TypeAlias</code></li></ul>`,35),o=[p];function l(c,i){return s(),a("div",null,o)}const r=n(t,[["render",l],["__file","manager.html.vue"]]),d=JSON.parse('{"path":"/en/dev/api/core/manager.html","title":"liteyuki.core.manager","lang":"en-US","frontmatter":{"title":"liteyuki.core.manager","description":"class ChannelDeliver method __init__(self, active: Channel[Any], passive: Channel[Any], channel_deliver_active: Channel[Channel[Any]], channel_deliver_passive: Channel[tuple[str...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/core/manager.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/core/manager.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.core.manager"}],["meta",{"property":"og:description","content":"class ChannelDeliver method __init__(self, active: Channel[Any], passive: Channel[Any], channel_deliver_active: Channel[Channel[Any]], channel_deliver_passive: Channel[tuple[str..."}],["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.core.manager\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-29T06:19:39.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"class ChannelDeliver","slug":"class-channeldeliver","link":"#class-channeldeliver","children":[]},{"level":3,"title":"method __init__(self, active: Channel[Any], passive: Channel[Any], channel_deliver_active: Channel[Channel[Any]], channel_deliver_passive: Channel[tuple[str, dict]], publish: Channel[tuple[str, Any]])","slug":"method-init-self-active-channel-any-passive-channel-any-channel-deliver-active-channel-channel-any-channel-deliver-passive-channel-tuple-str-dict-publish-channel-tuple-str-any","link":"#method-init-self-active-channel-any-passive-channel-any-channel-deliver-active-channel-channel-any-channel-deliver-passive-channel-tuple-str-dict-publish-channel-tuple-str-any","children":[]},{"level":3,"title":"class ProcessManager","slug":"class-processmanager","link":"#class-processmanager","children":[]},{"level":3,"title":"method __init__(self, lifespan: Lifespan)","slug":"method-init-self-lifespan-lifespan","link":"#method-init-self-lifespan-lifespan","children":[]},{"level":3,"title":"async method _run_process(self, name: str)","slug":"async-method-run-process-self-name-str","link":"#async-method-run-process-self-name-str","children":[]},{"level":3,"title":"async method start_all(self)","slug":"async-method-start-all-self","link":"#async-method-start-all-self","children":[]},{"level":3,"title":"method add_target(self, name: str, target: TARGET_FUNC, args: tuple = (), kwargs = None)","slug":"method-add-target-self-name-str-target-target-func-args-tuple-kwargs-none","link":"#method-add-target-self-name-str-target-target-func-args-tuple-kwargs-none","children":[]},{"level":3,"title":"method join_all(self)","slug":"method-join-all-self","link":"#method-join-all-self","children":[]},{"level":3,"title":"method terminate(self, name: str)","slug":"method-terminate-self-name-str","link":"#method-terminate-self-name-str","children":[]},{"level":3,"title":"method terminate_all(self)","slug":"method-terminate-all-self","link":"#method-terminate-all-self","children":[]},{"level":3,"title":"method is_process_alive(self, name: str) -> bool","slug":"method-is-process-alive-self-name-str-bool","link":"#method-is-process-alive-self-name-str-bool","children":[]},{"level":3,"title":"var TARGET_FUNC = Callable[..., Any]","slug":"var-target-func-callable-any","link":"#var-target-func-callable-any","children":[]}],"git":{"createdTime":1724234361000,"updatedTime":1724912379000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":2}]},"readingTime":{"minutes":2.28,"words":685},"filePathRelative":"en/dev/api/core/manager.md","localizedDate":"August 21, 2024","autoDesc":true}');export{r as comp,d as data};
|