how to handle network failures
grahn+nntp at snipabacken.se
Sun Oct 10 14:44:50 CEST 2010
On Fri, 2010-10-08, harryos wrote:
> I am trying to write a DataGrabber which reads some data from given
> url..I made DataGrabber as a Thread and want to wait for some interval
> of time in case there is a network failure that prevents read().
> I am not very sure how to implement this
> class DataGrabber(threading.Thread):
> def __init__(self,url):
> def run(self):
> def get_page_data():
> except IOError:
> #wait for some time and try again
> return data
> Is this the way to implement the part where the thread waits and
> reads the data again? Will this handle network failures?Can somebody
> please help?
You are using TCP sockets. When you get an error on one of those, the
TCP connection is dead (except for a few special cases like EAGAIN,
But you also risk *not* getting told and hanging forever, or anyway
for far longer than your application is likely to want to wait. For
example if the peer host is suddenly disconnected from the network --
TCP will keep trying, in case a connection suddenly reappears much
Try provoking that situation and see what happens.
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
More information about the Python-list