mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2025-07-28 08:00:56 +00:00
⚡ 添加进程及生命周期管理器,添加轻雪框架支持
This commit is contained in:
3
liteyuki/core/__init__.py
Normal file
3
liteyuki/core/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .spawn_process import *
|
||||
|
||||
|
37
liteyuki/core/spawn_process.py
Normal file
37
liteyuki/core/spawn_process.py
Normal file
@ -0,0 +1,37 @@
|
||||
import threading
|
||||
from multiprocessing import get_context, Event
|
||||
|
||||
import nonebot
|
||||
from nonebot import logger
|
||||
|
||||
from liteyuki.plugin.load import load_plugins
|
||||
|
||||
timeout_limit: int = 20
|
||||
__all__ = [
|
||||
"ProcessingManager",
|
||||
"nb_run",
|
||||
]
|
||||
|
||||
|
||||
class ProcessingManager:
|
||||
event: Event = None
|
||||
|
||||
@classmethod
|
||||
def restart(cls, delay: int = 0):
|
||||
"""
|
||||
发送终止信号
|
||||
Args:
|
||||
delay: 延迟时间,默认为0,单位秒
|
||||
Returns:
|
||||
"""
|
||||
if cls.event is None:
|
||||
raise RuntimeError("ProcessingManager has not been initialized.")
|
||||
if delay > 0:
|
||||
threading.Timer(delay, function=cls.event.set).start()
|
||||
return
|
||||
cls.event.set()
|
||||
|
||||
|
||||
def nb_run(event, *args, **kwargs):
|
||||
ProcessingManager.event = event
|
||||
nonebot.run(*args, **kwargs)
|
Reference in New Issue
Block a user