LiteyukiBot/liteyuki/core/spawn_process.py

38 lines
833 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)