Change in vdsm[master]: misc: Use with statement instead of try finally

nsoffer at redhat.com nsoffer at redhat.com
Wed Jun 11 15:47:06 UTC 2014


Nir Soffer has uploaded a new change for review.

Change subject: misc: Use with statement instead of try finally
......................................................................

misc: Use with statement instead of try finally

Using with make the code much more readable and ensure that you cannot
forget to release a lock, or place the try finally incorrectly.

We probably can fix this in other places, but since this is very
delicate code, it is best to do this is tiny steps.

Change-Id: I8fb6485850381dfbba56c5f08feaa826045e28a6
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M vdsm/storage/misc.py
1 file changed, 2 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/11/28611/1

diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index c5777b0..007c733 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -669,8 +669,7 @@
         >>    print "Do stuff"
         >>    dynamicBarrier.exit()
         """
-        self._cond.acquire()
-        try:
+        with self._cond:
             if self._lock.acquire(False):
                 return True
 
@@ -682,16 +681,10 @@
             self._cond.wait()
             return False
 
-        finally:
-            self._cond.release()
-
     def exit(self):
-        self._cond.acquire()
-        try:
+        with self._cond:
             self._lock.release()
             self._cond.notifyAll()
-        finally:
-            self._cond.release()
 
 
 class SamplingMethod(object):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8fb6485850381dfbba56c5f08feaa826045e28a6
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list