如何在python select()中增加filedescriptor的范围

ult*_*ain 3 python sockets select file-descriptor

我测试python socket编程.并修改如下所示的选项在Mac中

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 100000
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 709
virtual memory          (kbytes, -v) unlimited
Run Code Online (Sandbox Code Playgroud)

但是发生了以下错误.

Traceback (most recent call last):
  File "ssub.py", line 63, in createMqttClient
    rc = mqttc.loop()
  File "/Library/Python/2.7/site-packages/mosquitto.py", line 633, in loop
    socklist = select.select(rlist, wlist, [], timeout)
**ValueError: filedescriptor out of range in select()**
Run Code Online (Sandbox Code Playgroud)

增加filedescriptor如何写select ()函数?

Car*_*roo 5

select()支持的文件描述符数量有限制- 最简单的解决方案是简单地使用poll(),而不受此限制的影响.

严格来说,select()它可以支持的最高文件描述符受限,而不是给定调用中它们的数量 - 请参阅select()联机帮助页Notes部分的开头.我不确定OSX上有什么,但在Linux上它是1024.没有实用的方法来增加Python的这个限制.FD_SETSIZE

顺便说一句,如果你想保持可移植性,你可以考虑使用类似pyev的东西,这是一个围绕libev库的Python包装器,它使用在给定平台上等待IO的最佳方法.