[Python-Dev] timeout options in high-level networking modules

Charles Cazabon python at discworld.dyndns.org
Thu Dec 22 17:35:41 CET 2005


Steve Holden <steve at holdenweb.com> wrote:
> Jim Fulton wrote:
> > Yesterday, I needed to make a web request in a program (actually a test)
> > that could block indefinately, so I needed to set a socket timeout.
> > Unfortunately, AFAICT none of urllib, urllib2, httplib provide options to set
> > the timeout on the sockets they use.  I ended up having to roll my own
> > code to make the request.
[...]
> That's a very good idea. At present the only option one has is to set a 
> global socket.defaulttimout() or somehow monkey-patch the modules you 
> want to use, and neither of those options are entirely satisfactory.
> 
> Basically any method that can create a new TCP connection should acquire 
> an optional timeout=None parameter, right?

Yes.  

It might also be nice if the modules that rely on blocking mode being set on
sockets (basically anything using socket.ssl()) actually explicitly set that
first.  Right now, if you do socket.setdefaulttimeout() to a non-None value
and then try to use anything that does SSL (poplib, imaplib), the connections
will quickly die.

Charles
-- 
-----------------------------------------------------------------------
Charles Cazabon                           <python at discworld.dyndns.org>
GPL'ed software available at:               http://pyropus.ca/software/
-----------------------------------------------------------------------


More information about the Python-Dev mailing list