While loop

Tino Wildenhain tino at wildenhain.de
Thu Mar 5 12:19:59 EST 2009


Hi,

Fab86 wrote:
> Hello,
> 
> I am currently working on my program which send queries to Yahoo and
> then saves them into a flatfile. The problem I have is that I need to
> conduct 200 searches and Yahoo typically times out during the search
> with an error. I have caught the error and told it to time.sleep(10)
> however I can only think of deleting the flatfile and starting again
> hoping that it will not time out again.
> 
> Is it possible to get the program to catch the exception, wait 10
> seconds, then carry of from where it was rather than starting again?
> 
> If so, could someone please inform me how to do this?

for search in range(200):
     for t in range(MAXRETRY):
     	try:
         	result=requestfromserver(...)
                 break
     	except IOError,e: # or whaterver error you get
             time.sleep(10)
             # log something ...
     else: # if above runs w/o break
         raise XYZError...() # define appropriate for your app

     # here you can work with result


HTH
Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20090305/5d6de025/attachment-0001.bin>


More information about the Python-list mailing list