A closed client socket appended into elist, but there is no exception in ex when select called. I don't known why, can you help me please. Thanks so much!
r,w,ex = select.select(rlist, wlist,elist )
for s in ex:
print "catch a closed socket error!"
To catch a socket being closed event you need to have the socket in rlist
. When a connection is closed on the other side, select
returns and denotes that the closed socket is ready for reading (i.e. it's in you r
list). If you perform recv
on this socket and it returns an empty list (nothing has been read), it means a connection has been closed.
data = s.recv(size)
if not data:
# socket has been closed by peer
s.close()
From what I have seen, the exception list (the last parameter of select) isn't widely used. The main problem with it is that different OSes interpret this parameter differently. Sometimes it's even used only for cases that don't seem to be exceptions at all (OOB data).
socket
module documentation isn't specific about what that argument means, so it's generally not a good idea to rely on it:
xlist: wait for an “exceptional condition” (see the manual page for what your system considers such a condition)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With