New submission from Georg Brandl:
-------- Original-Nachricht --------
Betreff: [docs] socket.fileno() documentation
Datum: Thu, 10 Oct 2013 19:27:35 +0200
Von: Vlado Potisk <[email protected]>
An: [email protected]
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.
----------
assignee: docs@python
components: Documentation
messages: 199592
nosy: docs@python, georg.brandl
priority: normal
severity: normal
status: open
title: socket.fileno() documentation
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19234>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com