[rqlhelper] use threading.Lock as context manager
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 23 Apr 2015 14:45:42 +0200
changeset 763 c57010cac86c
parent 762 5aa92d744e2d
child 764 d5a8b1744cfa
[rqlhelper] use threading.Lock as context manager
rql/__init__.py
--- a/rql/__init__.py	Thu Jan 08 17:50:00 2015 +0100
+++ b/rql/__init__.py	Thu Apr 23 14:45:42 2015 +0200
@@ -105,25 +105,18 @@
         Each solution is a dictionary with variable's name as key and
         variable's type as value.
         """
-        self._analyser_lock.acquire()
-        try:
+        with self._analyser_lock:
             return self._analyser.visit(rqlst, uid_func_mapping, kwargs,
                                         debug)
-        finally:
-            self._analyser_lock.release()
 
     def compute_all_solutions(self, rqlst, uid_func_mapping=None, kwargs=None,
                           debug=False):
-        """compute syntaxe tree solutions with all types restriction (eg
+        """compute syntax tree solutions with all types restriction (eg
         is/instance_of relations) ignored
         """
-        self._itr_analyser_lock.acquire()
-        try:
+        with self._itr_analyser_lock:
             self._itr_analyser.visit(rqlst, uid_func_mapping, kwargs,
-                                 debug)
-        finally:
-            self._itr_analyser_lock.release()
-
+                                     debug)
 
     def simplify(self, rqlst):
         """Simplify `rqlst` by rewriting non-final variables associated to a const