Message199592
-------- Original-Nachricht --------
Betreff: [docs] socket.fileno() documentation
Datum: Thu, 10 Oct 2013 19:27:35 +0200
Von: Vlado Potisk <vlado@poti.sk>
An: docs@python.org
I might be wrong but in my opinion the socket library documentation is not
clear enough regarding the behaviour of the fileno() method in a case of a
failure.
In the Python 3.2 socket library documentation there is:
----
exception socket.error
A subclass of IOError, this exception is raised for socket-related errors.
-----
socket.close()
Close the socket. All future operations on the socket object will fail.
----
socket.fileno()
Return the socket’s file descriptor (a small integer).
----
Based on the information quoted above, I wrote a test if a socket is active or
if it has been closed already:
try:
sock.fileno()
except socket.error:
return False
return True
But is doesn't work. I have found out that fileno() returns -1 on a closed
socket. Replacing fileno() with e.g. getsockname() fixes the code.
It looks like a fileno's failure - unlike to getsockname's failure - is not
expressed by raising an exception, but by returning -1. However this seems to
be not documented and that's why I'm unsure if I may rely on this. |
|
Date |
User |
Action |
Args |
2013-10-12 16:33:57 | georg.brandl | set | recipients:
+ georg.brandl, docs@python |
2013-10-12 16:33:57 | georg.brandl | link | issue19234 messages |
2013-10-12 16:33:57 | georg.brandl | create | |
|