summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico2012-02-07 02:52:32 (GMT)
committerZac Medico2012-02-07 19:12:11 (GMT)
commit839f369f259a7c019c1f544bf4c153058355f6d4 (patch)
treea4f1a63e233d8b35c4883c90df3e076bd3770c05
parente9d1125f6730c85c4b384a580da55da68338acf1 (diff)
AsynchronousTask: merge _waiting from subclass
-rw-r--r--pym/_emerge/AsynchronousLock.py7
-rw-r--r--pym/_emerge/AsynchronousTask.py10
2 files changed, 10 insertions, 7 deletions
diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py
index ae3bde4..3593834 100644
--- a/pym/_emerge/AsynchronousLock.py
+++ b/pym/_emerge/AsynchronousLock.py
@@ -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):
diff --git a/pym/_emerge/AsynchronousTask.py b/pym/_emerge/AsynchronousTask.py
index 36522ca..4aa5980 100644
--- a/pym/_emerge/AsynchronousTask.py
+++ b/pym/_emerge/AsynchronousTask.py
@@ -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