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