On Fri, 2006-06-30 at 13:58 +0000, Patty wrote:
> Hi all,
> I'm doing some failure testing for a python script that uses urllib and
> urllib2
> to open a web page and post data. If the server's apache is down or if I
> change
> the ip address the script is trying to contact to be a bogus address, the
> script
> handles it prefectly. When I unplug the ethernet cable from my machine
> (client),
> the script hangs. Is there a way I can implement a timeout to handle this
> problem?
import socket
if not socket.getdefaulttimeout():
socket.setdefaulttimeout(25.0)
This sets a timout of 25 seconds. You need to set the timeout BEFORE
using a socket. The documentation is in the socket module, should you
need more detail. This technique works for simple cases.
> I'd appreciate any suggestions because I'm clueless.
> Thanks,
> Patty
>
> _______________________________________________
> Tutor maillist - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
--
Lloyd Kvam
Venix Corp
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor