Change in vdsm[master]: add exception ignoring utility

asegurap at redhat.com asegurap at redhat.com
Mon Aug 5 12:51:47 UTC 2013


Antoni Segura Puimedon has uploaded a new change for review.

Change subject: add exception ignoring utility
......................................................................

add exception ignoring utility

It is a common pattern to have:

    try:
        func()
    except PermissibleException:
        pass

With this patch, one can:

    with ignored(PermissibleException):
        func()

Which is more readable as the reader knows from the start what's
going to happend to the exceptions.

Change-Id: Ib043b027be306c8f9a9207f52cb1377e62b56dbc
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M lib/vdsm/utils.py
1 file changed, 8 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/61/17661/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index 538498f..5587550 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -27,6 +27,7 @@
     Contains a reverse dictionary pointing from error string to its error code.
 """
 from collections import namedtuple
+from contextlib import contextmanager
 from SimpleXMLRPCServer import SimpleXMLRPCServer
 from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
 from StringIO import StringIO
@@ -912,3 +913,10 @@
     logging.error("Panic: %s", msg, exc_info=True)
     os.killpg(0, 9)
     sys.exit(-3)
+
+
+def ignored(*exceptions):
+    try:
+        yield
+    except exceptions:
+        pass


-- 
To view, visit http://gerrit.ovirt.org/17661
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib043b027be306c8f9a9207f52cb1377e62b56dbc
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>


More information about the vdsm-patches mailing list