1
0
forked from bot/app

🐛 fix 通道类回调函数在进程间传递时无法序列号的问题

This commit is contained in:
2024-08-10 22:25:41 +08:00
parent 3bd40e7271
commit 7107d03b72
66 changed files with 5112 additions and 4916 deletions

View File

@ -3,6 +3,7 @@ from typing import Optional, TYPE_CHECKING
import nonebot
from liteyuki.core.nb import adapter_manager, driver_manager
from liteyuki.comm.channel import set_channel
if TYPE_CHECKING:
from liteyuki.comm.channel import Channel
@ -10,23 +11,23 @@ if TYPE_CHECKING:
timeout_limit: int = 20
"""导出对象用于主进程与nonebot通信"""
chan_in_spawn_nb: Optional["Channel"] = None
_channels = {}
def nb_run(chan, *args, **kwargs):
def nb_run(chan_active: "Channel", chan_passive: "Channel", *args, **kwargs):
"""
初始化NoneBot并运行在子进程
Args:
chan:
*args:
chan_active:
chan_passive:
**kwargs:
Returns:
"""
global chan_in_spawn_nb
chan_in_spawn_nb = chan
set_channel("nonebot-active", chan_active)
set_channel("nonebot-passive", chan_passive)
nonebot.init(**kwargs)
driver_manager.init(config=kwargs)
adapter_manager.init(kwargs)
@ -35,17 +36,21 @@ def nb_run(chan, *args, **kwargs):
nonebot.run()
def mb_run(chan, *args, **kwargs):
def mb_run(chan_active: "Channel", chan_passive: "Channel", *args, **kwargs):
"""
初始化MeloBot并运行在子进程
Args:
chan
chan_active
chan_passive
*args:
**kwargs:
Returns:
"""
set_channel("melobot-active", chan_active)
set_channel("melobot-passive", chan_passive)
# bot = MeloBot(__name__)
# bot.init(AbstractConnector(cd_time=0))
# bot.run()