annotate python/example/retry.py @ 830:6de24d387889

remove old import
author Jeff Hammel <k0scist@gmail.com>
date Sun, 19 Feb 2017 17:55:23 -0800
parents 88f19ebb43ea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
758
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 def retry(f, retries=5, args=(), kw=None, exceptions=()):
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 kw = kw or {}
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 for index in range(retries):
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 try:
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 return f(*args, **kw)
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 except Exception as e:
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 if isinstance(e, exceptions):
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 print ("something bad happen")
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 else:
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 raise
88f19ebb43ea add example retry function
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 raise RetryTimeout("Tries a bunch of times :(")