<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> channel_passive.send(</span><spanstyle="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"I am liteyuki main process passive"</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> channel_active.send(</span><spanstyle="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"I am liteyuki main process active"</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> data </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> active_channel.receive()</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> logger.info(</span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">f</span><spanstyle="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"Active receive: </span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">data</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><spanstyle="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><blockquote><p>启动后控制台输出</p></blockquote><divclass="language-log vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">log</span><preclass="shiki shiki-themes github-light github-dark vp-code"tabindex="0"><code><spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">0000-00-00</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> 00:00:00</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ℹ️信息] Passive receive: I am liteyuki main process passive</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">0000-00-00</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> 00:00:00</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ℹ️信息] Active receive: I am liteyuki main process active</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">0000-00-00</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> 00:00:03</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ℹ️信息] Passive receive: I am liteyuki main process passive</span></span>
<spanclass="line"><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;">0000-00-00</span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> 00:00:03</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> [ℹ️信息] Active receive: I am liteyuki main process active</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">...</span></span></code></pre></div><h2id="共享内存通信"tabindex="-1"><strong>共享内存通信</strong><aclass="header-anchor"href="#共享内存通信"aria-label="Permalink to "**共享内存通信**""></a></h2><h3id="简介"tabindex="-1">简介 <aclass="header-anchor"href="#简介"aria-label="Permalink to "简介""></a></h3><ul><li>相比于普通进程通信,内存共享使得代码编写更加简洁,轻雪框架提供了一个内存共享通信的接口,你可以通过<code>storage</code>模块实现内存共享通信,该模块封装通道实现</li><li>内存共享是线程安全的,你可以在多个线程中读写共享内存,线程锁会自动保护共享内存的读写操作</li></ul><h3id="示例"tabindex="-1">示例 <aclass="header-anchor"href="#示例"aria-label="Permalink to "示例""></a></h3><blockquote><p>在任意进程中均可使用</p></blockquote><divclass="language-python vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">python</span><preclass="shiki shiki-themes github-light github-dark vp-code"tabindex="0"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> liteyuki.comm.storage </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shared_memory</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">value </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> shared_memory.get(</span><spanstyle="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"key"</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><spanstyle="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 获取共享内存</span></span></code></pre></div><p>源代码:<ahref="https://github.com/LiteyukiStudio/LiteyukiBot/blob/main/liteyuki/comm/storage.py"target="_blank"rel="noreferrer">liteyuki/comm/storage.py</a></p></div></div></main><footerclass="VPDocFooter"data-v-f55f7f94data-v-357376a2><!--[--><!--]--><divclass="edit-info"data-v-357376a2><divclass="edit-link"data-v-357376a2><aclass="VPLink link vp-external-link-icon no-icon edit-link-button"href="https://github.com/LiteyukiStudio/LiteyukiBot/tree/main/docs/en/dev/comm.md"target="_blank"rel="noreferrer"data-v-357376a2><!--[--><spanclass="vpi-square-pen edit-link-icon"data-v-357376a2></span> Edit this page on GitHub<!--]--></a></div><divclass="last-updated"data-v-357376a2><pclass="VPLastUpdated"data-v-357376a2data-v-d67734f1>Last updated: <timedatetime="2024-09-20T19:12:32.000Z"data-v-d67734f1></time></p></div></div><navclass="prev-next"aria-labelledby="doc-footer-aria-label"data-v-357376a2><spanclass="visually-hidden"id="doc-footer-aria-label"data-v-357376a2>Pager</span><divclass="pager"data-v-357376a2><aclass="VPLink link pager-link prev"href="/en/dev/plugin.html"data-v-357376a2><!--[--><spanclass="desc"data-v-357376a2>Prev Page</span><spanclass="title"data-v-357376a2>Plugin</span><!--]--></a></div><divclass="pager"data-v-357376a2><aclass="VPLink link pager-link next"href="/en/dev/best_practices.html"data-v-357376a2><!--[--><spanclass="desc"data-v-357376a2>Next Page</span><spanclass="title"data-v-357376a2>Best Practices</span><!--]--></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footerclass="VPFooter has-sidebar"data-v-1b006de6data-v-a24a2a6f><divclass="container"data-v-a24a2a6f><pclass="message"data-v-a24a2a6f>Documentation built with <ahref="https://vitepress.dev/">VitePress</a> | API references generated by <ahref="https://github.com/LiteyukiStudio/litedoc">litedoc</a></p><pclass="copyright"data-v-a24a2a6f>Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved</p></div></footer><!--[--><!--]--></div></div>