Skip to content

Instantly share code, notes, and snippets.

@netmarkjp
Last active December 28, 2015 20:49
Show Gist options
  • Save netmarkjp/7559988 to your computer and use it in GitHub Desktop.
Save netmarkjp/7559988 to your computer and use it in GitHub Desktop.
import time
def check_hoge(**args):
print "args:",
print args
return False
def wait(function_name, retry=5, interval=1, **args):
try_count = 1
while not globals()[function_name](**args):
time.sleep(interval)
if try_count > retry:
raise Exception("retry over tried %d times" % try_count)
try_count = try_count + 1
try:
print "retry 2"
wait("check_hoge", 2, 1, myarg1=10, myarg2=20)
except Exception as e:
print e
try:
print "retry 1"
wait("check_hoge", 1, 1, myarg1=10, myarg2=20)
except Exception as e:
print e
try:
print "retry 0"
wait("check_hoge", 0, 1, myarg1=10, myarg2=20)
except Exception as e:
print e
@netmarkjp
Copy link
Author

use globals()[function_name] or getattr(self,function_name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment