I have some code to perform an exponential backoff. I am interacting with a few different web services. Checking for a specific Exception and then re-invoking the failed call after waiting a bit. I don't want to code the backoff in ten different places. Really miss the C pre-processor.
I am tempted to try something like the following, but I understand that eval should be a last resort. Any pythonic best practice for this situation?: from time import sleep from random import randint def exponentialbackoff(exception,numretrys,somecode): currentIteration=0 SuccessfulCall=False rc=None globalnamespace=getglobals(,globals) while currentiteration<numretrys: try: rc=eval(somecode,globalnamespace) SuccessfulCall=True break except exception: currentiteration = currentiteration+1 sleepytime=randint(0,4**currentiteration) sleep(sleepytime) return (SuccessfulCall,rc) --- Gil Cosson Bremerton, Washington 360 620 0431
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor