1 |
Group together the sync operation and the callback as a single task, |
2 |
so that the callback will not execute concurrently with another sync |
3 |
operation for --jobs=1. |
4 |
|
5 |
X-Gentoo-Bug: 562264 |
6 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=562264 |
7 |
--- |
8 |
pym/portage/sync/controller.py | 39 +++++++++++++++++++++++++++++++++++---- |
9 |
1 file changed, 35 insertions(+), 4 deletions(-) |
10 |
|
11 |
diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py |
12 |
index 28dbc57..159b9c0 100644 |
13 |
--- a/pym/portage/sync/controller.py |
14 |
+++ b/pym/portage/sync/controller.py |
15 |
@@ -25,6 +25,7 @@ from portage.util._async.AsyncFunction import AsyncFunction |
16 |
from portage import OrderedDict |
17 |
from portage import _unicode_decode |
18 |
from portage import util |
19 |
+from _emerge.CompositeTask import CompositeTask |
20 |
|
21 |
|
22 |
class TaskHandler(object): |
23 |
@@ -119,10 +120,9 @@ class SyncManager(object): |
24 |
self.settings, self.trees, self.mtimedb = emerge_config |
25 |
self.xterm_titles = "notitles" not in self.settings.features |
26 |
self.portdb = self.trees[self.settings['EROOT']]['porttree'].dbapi |
27 |
- proc = AsyncFunction(target=self.sync, |
28 |
- kwargs=dict(emerge_config=emerge_config, repo=repo)) |
29 |
- proc.addExitListener(self._sync_callback) |
30 |
- return proc |
31 |
+ return SyncRepo(sync_task=AsyncFunction(target=self.sync, |
32 |
+ kwargs=dict(emerge_config=emerge_config, repo=repo)), |
33 |
+ sync_callback=self._sync_callback) |
34 |
|
35 |
def sync(self, emerge_config=None, repo=None): |
36 |
self.callback = None |
37 |
@@ -343,3 +343,34 @@ class SyncManager(object): |
38 |
action_metadata(self.settings, self.portdb, self.emerge_config.opts, |
39 |
porttrees=[repo.location]) |
40 |
|
41 |
+ |
42 |
+class SyncRepo(CompositeTask): |
43 |
+ """ |
44 |
+ Encapsulates a sync operation and the callback which executes afterwards, |
45 |
+ so both can be considered as a single composite task. This is useful |
46 |
+ since we don't want to consider a particular repo's sync operation as |
47 |
+ complete until after the callback has executed (bug 562264). |
48 |
+ |
49 |
+ The kwargs and result properties expose attributes that are accessed |
50 |
+ by SyncScheduler. |
51 |
+ """ |
52 |
+ |
53 |
+ __slots__ = ('sync_task', 'sync_callback') |
54 |
+ |
55 |
+ @property |
56 |
+ def kwargs(self): |
57 |
+ return self.sync_task.kwargs |
58 |
+ |
59 |
+ @property |
60 |
+ def result(self): |
61 |
+ return self.sync_task.result |
62 |
+ |
63 |
+ def _start(self): |
64 |
+ self._start_task(self.sync_task, self._sync_task_exit) |
65 |
+ |
66 |
+ def _sync_task_exit(self, sync_task): |
67 |
+ self._current_task = None |
68 |
+ self.returncode = sync_task.returncode |
69 |
+ self.sync_callback(self.sync_task) |
70 |
+ self._async_wait() |
71 |
+ |
72 |
-- |
73 |
2.4.6 |