mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 12:33:56 +08:00
@@ -805,6 +805,9 @@ class ConnectionHandler:
|
|||||||
type, text, audio_data, report_time = item
|
type, text, audio_data, report_time = item
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# 检查线程池状态
|
||||||
|
if self.executor is None:
|
||||||
|
continue
|
||||||
# 提交任务到线程池
|
# 提交任务到线程池
|
||||||
self.executor.submit(
|
self.executor.submit(
|
||||||
self._process_report, type, text, audio_data, report_time
|
self._process_report, type, text, audio_data, report_time
|
||||||
@@ -835,7 +838,7 @@ class ConnectionHandler:
|
|||||||
|
|
||||||
async def close(self, ws=None):
|
async def close(self, ws=None):
|
||||||
"""资源清理方法"""
|
"""资源清理方法"""
|
||||||
|
try:
|
||||||
# 取消超时任务
|
# 取消超时任务
|
||||||
if self.timeout_task:
|
if self.timeout_task:
|
||||||
self.timeout_task.cancel()
|
self.timeout_task.cancel()
|
||||||
@@ -849,6 +852,16 @@ class ConnectionHandler:
|
|||||||
if self.stop_event:
|
if self.stop_event:
|
||||||
self.stop_event.set()
|
self.stop_event.set()
|
||||||
|
|
||||||
|
# 等待上报队列处理完成
|
||||||
|
if hasattr(self, "report_queue"):
|
||||||
|
try:
|
||||||
|
# 添加毒丸对象
|
||||||
|
self.report_queue.put(None)
|
||||||
|
# 等待队列处理完成
|
||||||
|
self.report_queue.join()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.bind(tag=TAG).error(f"等待上报队列处理完成时出错: {e}")
|
||||||
|
|
||||||
# 清空任务队列
|
# 清空任务队列
|
||||||
self.clear_queues()
|
self.clear_queues()
|
||||||
|
|
||||||
@@ -864,6 +877,8 @@ class ConnectionHandler:
|
|||||||
self.executor = None
|
self.executor = None
|
||||||
|
|
||||||
self.logger.bind(tag=TAG).info("连接资源已释放")
|
self.logger.bind(tag=TAG).info("连接资源已释放")
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.bind(tag=TAG).error(f"关闭连接时出错: {e}")
|
||||||
|
|
||||||
def clear_queues(self):
|
def clear_queues(self):
|
||||||
"""清空所有任务队列"""
|
"""清空所有任务队列"""
|
||||||
|
|||||||
Reference in New Issue
Block a user