Time out question

Alex Martelli aleax at mac.com
Sun Jul 2 20:57:23 EDT 2006


DarkBlue <nomail at nixmail.com> wrote:

> My application makes several connections to
> a remote database server via tcp/ip.
> Usually all is fine,but occasionally the server is
> down or the internet does not work and then there is
> the 30 sec to several minutes timeout wait for the
> tcp to give up.
> Is there anything I can do without using 
> threads,sockets,twisted etc. to have following :
> 
> pseudocode :
> 
>  try for 10 seconds
>    if database.connected :
>     do your remote thing
>  except raise after 10 seconds
>    abort any connection attempt
>    do something else 

Sure, see function setdefaulttimeout in module socket.  Just call it as
you wish before trying the DB connection and catch the resulting
exception.


Alex



More information about the Python-list mailing list