wzpan / wukong-robot

🤖 wukong-robot 是一个简单、灵活、优雅的中文语音对话机器人/智能音箱项目,支持ChatGPT多轮对话能力,还可能是首个支持脑机交互的开源智能音箱项目。

Home Page:https://wukong.hahack.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RuntimeError: cannot schedule new futures after interpreter shutdown请问这个问题怎么解决?

yxn4065 opened this issue · comments

确认已寻找过答案

我已确认在 Github issue 页、常见问题页、文档 中都查找过,没有找到类似问题和资料。我也没有 google / bing/ 百度 / duckduckgo 到相关解答。

这个错误信息表明在 Python 解释器关闭后,尝试调度新的 concurrent.futures.Future 对象时发生了异常。具体来说,在 Conversation.py 文件的 _tts 方法中,当尝试使用线程池(pool)的 submit 方法提交新任务时,Python 解释器已经处于关闭状态,因此不允许再调度新的任务。

这种情况通常发生在以下几种情况:

程序正在退出,而某个线程或回调尝试提交新任务。
使用了信号处理器来优雅地关闭程序,但在关闭过程中,仍有代码尝试提交新任务。
程序的其他部分存在资源管理问题,导致解释器过早关闭。

安装方式

手动安装

操作系统

树莓派4B 64bit

离线唤醒相关

问题描述

2024-04-06 13:18:09,707 - tornado.application - web.py - log_exception - line 1871 - ERROR - Uncaught exception POST /chat (192.168.137.1)
HTTPServerRequest(protocol='http', host='192.168.137.252:5001', method='POST', uri='/chat', version='HTTP/1.1', remote_ip='192.168.137.1')
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.11/site-packages/tornado/web.py", line 1784, in _execute
result = method(*self.path_args, **self.path_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/souce_code/wukong-robot/server/server.py", line 170, in post
conversation.doResponse(
File "/home/pi/souce_code/wukong-robot/robot/Conversation.py", line 173, in doResponse
self.say(msg, True, onCompleted=self.checkRestore)
File "/home/pi/souce_code/wukong-robot/robot/Conversation.py", line 405, in say
audios = self._tts(lines, cache, onCompleted)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/souce_code/wukong-robot/robot/Conversation.py", line 316, in _tts
task = pool.submit(
^^^^^^^^^^^^
File "/usr/lib/python3.11/concurrent/futures/thread.py", line 169, in submit
raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown
2024-04-06 13:18:09,718 - tornado.access - web.py - log_request - line 2344 - ERROR - 500 POST /chat (192.168.137.1) 2760.01ms

开始时候正常,第二次对话无应答,提示服务器错误
image

问题有解决吗?

根本原因是主线程已经结束了,而子线程去尝试一个新的任务,解决办法很简单:
在server/server.py的run方法里,t.start()下面加一行:t.join(),就可以等子线程结束再结束主线程