Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase filedescriptor's range in python select()

I test python socket programming. And Modify the options as shown below was in 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

But The following error has occurred.

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()**

increase the filedescriptor how to write select () function?

like image 255
ultrakain Avatar asked Jan 10 '13 04:01

ultrakain


1 Answers

There is a limit to the number of file descriptors that select() supports - the easiest solution is to simply use poll() instead, which doesn't suffer from this limit.

Strictly speaking, select() is limited in the highest file descriptor it can support, as opposed to the number of them in a given call - see the start of the Notes section of the select() manpage. I'm not sure what FD_SETSIZE is on OSX, but on Linux it's 1024. There's no practical way to increase this limit from Python.

As an aside, if you want to keep things portable you might consider using something like pyev which is a Python wrapper around libev library which uses the optimal method of waiting for IO on a given platform.

like image 130
Cartroo Avatar answered Nov 01 '22 11:11

Cartroo