Why can not select.select () catch a private socket error?

Closed client socket added to elist but an exception in ex when select is called. I don’t know why, can you help me. Thank you very much!

r,w,ex = select.select(rlist, wlist,elist ) for s in ex: print "catch a closed socket error!" 
+4
source share
1 answer

To catch a private socket event, you need to have a socket in rlist . When the connection is closed on the other hand, select returned and indicates that the closed connector is ready to be read (i.e., in list r ). If you execute recv on this socket and it returns an empty list (nothing was read), this means that the connection was closed.

  data = s.recv(size) if not data: # socket has been closed by peer s.close() 

From what I saw, the exception list (the last selection option) is not widely used. The main problem is that different operating systems interpret this parameter differently. Sometimes it was even used only for cases that are not exceptions at all (OOB data).

Module documentation

socket not specific to what this argument means, so you should generally not rely on it:

xlist: wait for the "exceptional condition" (see the manual page for what your system considers this condition)

+4
source

All Articles