Skip to content

Instantly share code, notes, and snippets.

@thejhh
Created April 6, 2016 15:34
Show Gist options
  • Select an option

  • Save thejhh/fa43de1d12c57f3ec68d8e0778a760b2 to your computer and use it in GitHub Desktop.

Select an option

Save thejhh/fa43de1d12c57f3ec68d8e0778a760b2 to your computer and use it in GitHub Desktop.
# Start
counter = 0
while 1:
try:
counter += 1
print("Start")
node.qemu(vps.vmid).status.start.create()
break
except ResourceException as e:
if counter >= 10: raise
elog(e)
print("Proxmox Error? I will try again in a moment.")
sleep(1)
@nailor

nailor commented Apr 6, 2016

Copy link
Copy Markdown

Context Manager vois auttaa?

class ResourceExceptionManager(object):
    def __init__(self, fn):
        self.fn = fn

    def __enter__(self):
        for _ in range(0, 10):
            try:
                return self.fn()
            except ResourceException as e:
                sleep(1)
        else:
            raise e

     def __exit__(self, *args):
        return False

with ResourceExceptionManager(node.qemu(vps.vmid).status.start.create) as node:
     pass

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