测试线程发送。防止阻塞
This commit is contained in:
@@ -11,13 +11,10 @@ def send_message_in_thread(func, *args, **kwargs):
|
||||
"""在独立线程中发送消息"""
|
||||
def run():
|
||||
try:
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
loop.run_until_complete(func(*args, **kwargs))
|
||||
# 在新线程中运行异步函数
|
||||
asyncio.run(func(*args, **kwargs))
|
||||
except Exception as e:
|
||||
logger.error(f"发送消息失败: {e}")
|
||||
finally:
|
||||
loop.close()
|
||||
|
||||
# 创建并启动线程
|
||||
thread = threading.Thread(target=run)
|
||||
|
||||
Reference in New Issue
Block a user