[Python-ideas] Provide a more informative message on socket's bind() and connect*()

Giampaolo Rodola' g.rodola at gmail.com
Thu May 16 15:51:06 CEST 2013


Consider the following:

>>> import socket
>>> s = socket.socket()
>>> addr = ('', 8080)
>>> s.bind(addr)
Traceback (most recent call last):
  File "foo.py", line 29, in <module>
    s.bind(addr)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use

Problem here is that the information about the address passed to bind() is
lost.
While playing with Tulip I noticed some effort was put into providing a
more informative message:

https://code.google.com/p/tulip/source/browse/tulip/base_events.py?spec=svne05013a5516da73c97d9a11ece79283839e41bd0&r=f400984a064869a9326f5159ce7f6182087cb926#292

https://code.google.com/p/tulip/source/browse/tulip/base_events.py?spec=svne05013a5516da73c97d9a11ece79283839e41bd0&r=f400984a064869a9326f5159ce7f6182087cb926#449

I thought that maybe it makes sense to do that straight into the socket
module by either overriding bind() (and also connect() and connect_ex()) or
perhaps by providing a brand new PyErr_SetFromErrnoWithMsgObject() which
can also be used elsewhere.
Thoughts?

--- Giampaolo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130516/20e0f4a8/attachment.html>


More information about the Python-ideas mailing list