[New-bugs-announce] [issue19234] socket.fileno() documentation

Georg Brandl report at bugs.python.org
Sat Oct 12 18:33:57 CEST 2013


New submission from Georg Brandl:

-------- Original-Nachricht --------
Betreff: [docs] socket.fileno() documentation
Datum: Thu, 10 Oct 2013 19:27:35 +0200
Von: Vlado Potisk <vlado at poti.sk>
An: docs at 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.

----------
assignee: docs at python
components: Documentation
messages: 199592
nosy: docs at python, georg.brandl
priority: normal
severity: normal
status: open
title: socket.fileno() documentation

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19234>
_______________________________________


More information about the New-bugs-announce mailing list