annotate python/example/retry.py @ 921:02b31a76e2c4

get DEST from command line
author Jeff Hammel <k0scist@gmail.com>
date Sun, 02 Jun 2024 16:35:01 -0700
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 :(")