66import logging
77import time
88import random
9+ import urllib
910
1011from main import main
1112from utils import getDataDirectory
@@ -500,28 +501,28 @@ def runTestSession(pose='all',isDocker=True,maxNumTries=3):
500501 logging .info ("\n \n \n Status check succeeded. \n \n " )
501502 return
502503
503- # Catch and re-enter while loop if it's an HTTPError (could be more
504- # than just 404 errors). Wait between 30 and 60 seconds before
505- # retrying.
506- except requests .exceptions .HTTPError as e :
504+ # Catch and re-enter while loop if it's an HTTPError or URLError
505+ # (could be more than just 404 errors). Wait between 30 and 60 seconds
506+ # before retrying.
507+ except ( requests .exceptions .HTTPError , urllib . error . URLError ) as e :
507508 if numTries < maxNumTries :
508- logging .info (f"test trial failed on try #{ numTries } due to HTTPError. Retrying." )
509+ logging .info (f"test trial failed on try #{ numTries } due to HTTPError or URLError . Retrying." )
509510 wait_time = random .randint (30 ,60 )
510511 logging .info (f"waiting { wait_time } seconds then retrying..." )
511512 time .sleep (wait_time )
512513 continue
513514 else :
514- logging .info (f"test trial failed on try #{ numTries } due to HTTPError." )
515+ logging .info (f"test trial failed on try #{ numTries } due to HTTPError or URLError ." )
515516 # send email
516- message = "A backend OpenCap machine failed the status check (HTTPError). It has been stopped."
517+ message = "A backend OpenCap machine failed the status check (HTTPError or URLError ). It has been stopped."
517518 sendStatusEmail (message = message )
518- raise Exception ('Failed status check (HTTPError). Stopped.' )
519+ raise Exception ('Failed status check (HTTPError or URLError ). Stopped.' )
519520
520521 # Catch other errors and stop
521522 except :
522523 logging .info ("test trial failed. stopping machine." )
523524 # send email
524- message = "A backend OpenCap machine failed the status check. It has been stopped."
525+ message = "A backend OpenCap machine failed the status check (not HTTPError or URLError) . It has been stopped."
525526 sendStatusEmail (message = message )
526527 raise Exception ('Failed status check. Stopped.' )
527528
0 commit comments