A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-March/072154.html below:

[Python-Dev] Adding timeout to socket.py and httplib.py

[Python-Dev] Adding timeout to socket.py and httplib.py [Python-Dev] Adding timeout to socket.py and httplib.pyJosiah Carlson jcarlson at uci.edu
Tue Mar 20 22:16:57 CET 2007
Facundo Batista <facundo at taniquetil.com.ar> wrote:
> Josiah Carlson wrote:
> > sentinel = object()
> >
> > def connect(HOST, PORT, timeout=sentinel):
> >     ...
> >     if timeout is not sentinel:
> >         sock.settimeout(timeout)
> >     ...
> >
> > A keyword argument via **kwargs is also fine.  I have no preference.
> 
> I do. The way you showed here, I'm not restricting user options. I think
> this is better.

But the kwargs doesn't restrict options either...

def connect(address, **kwargs):
    ...
    if 'timeout' in kwargs:
        sock.settimeout(kwargs['timeout'])
    ...

With that method you can include timeout=None, and it also doesn't
restrict what the user could pass as a value to timeout.  It requires
that you pass timeout explicitly, but that's a (relatively
inconsequential) API decision.

 - Josiah

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4