ValueError:select中过多的文件描述符-Python-Flask-SocketIo-Threading

问题描述

我有一个使用python flask模块的Web应用程序,该模块具有flask_socketio实现,用于服务器和客户端之间的通信。客户端将调用应用程序中的API,该方法调用线程中的函数并返回响应。线程函数将发出多个HTTP请求,并获取套接字消息。

几个小时/几次执行后,我遇到了以下错误

(10160)wsgi退出,is_accepting = True 线程Thread-1中的异常: 追溯(最近一次通话): _bootstrap_inner中的第916行的文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ threading.py” self.run() 运行中的文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ threading.py”,行864 self._target(* self._args,** self。 kwargs) 在运行服务器中的第578行,文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ site-packages \ flask_socketio_ init .py” log_output = log_output,** kwargs) 服务器中的文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ site-packages \ eventlet \ wsgi.py”,行990 client_socket,client_addr = sock.accept() 接受文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ site-packages \ eventlet \ greenio \ base.py”,行230 self._trampoline(fd,read = True,timeout = self.gettimeout(),timeout_exc = _timeout_exc) 文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ site-packages \ eventlet \ greenio \ base.py”,行210,_trampoline mark_as_closed = self。 mark_as_closed) 第159行的蹦床文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ site-packages \ eventlet \ hubs_ init .py” 返回hub.switch() 开关中的文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ site-packages \ eventlet \ hubs \ hub.py”,行298 返回self.greenlet.switch() 运行中的文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ site-packages \ eventlet \ hubs \ hub.py”,行350 self.wait(睡眠时间) 文件“ C:\ Users \ test \ AppData \ Local \ Programs \ Python \ python36 \ lib \ site-packages \ eventlet \ hubs \ selects.py”,第42行,正在等待 r,w,er = select.select(reader_fds,writer_fds,all_fds,秒) ValueError:select()中的文件描述符过多

app = Flask(__name__)
app.config['SECRET_KEY'] = 'mysecret'
CORS(app)
socketIo = SocketIO(app,cors_allowed_origins="*")
app.debug = True
app.host = '0.0.0.0'


@socketIo.on("data")
def handleMessage(msg):
    socketIo.emit('data',msg)
    return None


@socketIo.on("connect")
def handleMessage():
    print('connect')
    return None


def sendMessage(msg):
    print('inside send message')
    socketIo.emit(('message','sending message from rest'))
    return None


@socketIo.on('disconnect')
def test_disconnect():
    print('Client disconnected')
    return None

app.register_blueprint(execution_blueprint)

if __name__ == '__main__':
    socketIo.run(app,host='0.0.0.0',port=5001)

线程:

class Compute(Thread):
    def __init__(self,data):
        Thread.__init__(self)
        self.data = data

    def run(self)
        execution(self.data)


def start_thread(data):
    thread_a = Compute(data)
    thread_a.start()
    return "Process Started in Background"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)