On Fri, 30 Jun 2006, Patty wrote: > I'm doing some failure testing for a python script that uses urllib and > urllib2 to open a web page and post data.... Is there a way I can > implement a timeout to handle this problem?
I don't have any firsth-hand knowledge on this, but http://www.voidspace.org.uk/python/articles/urllib2.shtml says: ------------------------------------ By default the socket module has no timeout and can hang. Currently, the socket timeout is not exposed at the httplib or urllib2 levels. However, you can set the default timeout globally for all sockets using : import socket import urllib2 # timeout in seconds timeout = 10 socket.setdefaulttimeout(timeout) # this call to urllib2.urlopen now uses the default timeout # we have set in the socket module req = urllib2.Request('http://www.voidspace.org.uk') response = urllib2.urlopen(req) ------------------------------------ Good luck! _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
