AsynchronousTask: merge _waiting from subclass
authorZac Medico <zmedico@gentoo.org>
Tue, 7 Feb 2012 02:52:32 +0000 (18:52 -0800)
committerZac Medico <zmedico@gentoo.org>
Tue, 7 Feb 2012 19:12:11 +0000 (11:12 -0800)
pym/_emerge/AsynchronousLock.py
pym/_emerge/AsynchronousTask.py

index ae3bde4d6a77d7465668c9e2ae467e5a5869cbbe..3593834f2c65e8a1a33e449df12745fc1a46c1d3 100644 (file)
@@ -36,7 +36,7 @@ class AsynchronousLock(AsynchronousTask):
 
        __slots__ = ('path', 'scheduler',) + \
                ('_imp', '_force_async', '_force_dummy', '_force_process', \
-               '_force_thread', '_waiting')
+               '_force_thread')
 
        _use_process_by_default = True
 
@@ -67,8 +67,7 @@ class AsynchronousLock(AsynchronousTask):
 
        def _imp_exit(self, imp):
                # call exit listeners
-               if not self._waiting:
-                       self.wait()
+               self.wait()
 
        def _cancel(self):
                if isinstance(self._imp, AsynchronousTask):
@@ -82,9 +81,7 @@ class AsynchronousLock(AsynchronousTask):
        def _wait(self):
                if self.returncode is not None:
                        return self.returncode
-               self._waiting = True
                self.returncode = self._imp.wait()
-               self._waiting = False
                return self.returncode
 
        def unlock(self):
index 36522ca4c941867566929df3659a61cf88b7289b..4aa5980857455979c57c9a09b0729f2cd8c1b96e 100644 (file)
@@ -14,7 +14,8 @@ class AsynchronousTask(SlotObject):
        """
 
        __slots__ = ("background", "cancelled", "returncode") + \
-               ("_exit_listeners", "_exit_listener_stack", "_start_listeners")
+               ("_exit_listeners", "_exit_listener_stack", "_start_listeners",
+               "_waiting")
 
        def start(self):
                """
@@ -42,7 +43,12 @@ class AsynchronousTask(SlotObject):
 
        def wait(self):
                if self.returncode is None:
-                       self._wait()
+                       if not self._waiting:
+                               self._waiting = True
+                               try:
+                                       self._wait()
+                               finally:
+                                       self._waiting = False
                self._wait_hook()
                return self.returncode