Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] SyncRepos.async: group sync and callback as composite task (bug 562264)
Date: Tue, 06 Oct 2015 07:02:51
Message-Id: 20151006000157.726cb6e5.dolsen@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] SyncRepos.async: group sync and callback as composite task (bug 562264) by Zac Medico
1 On Mon, 5 Oct 2015 16:04:16 -0700
2 Zac Medico <zmedico@g.o> wrote:
3
4 > Group together the sync operation and the callback as a single task,
5 > so that the callback will not execute concurrently with another sync
6 > operation for --jobs=1.
7 >
8 > X-Gentoo-Bug: 562264
9 > X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=562264
10 > ---
11 > pym/portage/sync/controller.py | 39
12 > +++++++++++++++++++++++++++++++++++---- 1 file changed, 35
13 > insertions(+), 4 deletions(-)
14 >
15 > diff --git a/pym/portage/sync/controller.py
16 > b/pym/portage/sync/controller.py index 28dbc57..159b9c0 100644
17 > --- a/pym/portage/sync/controller.py
18 > +++ b/pym/portage/sync/controller.py
19 > @@ -25,6 +25,7 @@ from portage.util._async.AsyncFunction import
20 > AsyncFunction from portage import OrderedDict
21 > from portage import _unicode_decode
22 > from portage import util
23 > +from _emerge.CompositeTask import CompositeTask
24 >
25 >
26 > class TaskHandler(object):
27 > @@ -119,10 +120,9 @@ class SyncManager(object):
28 > self.settings, self.trees, self.mtimedb =
29 > emerge_config self.xterm_titles = "notitles" not in
30 > self.settings.features self.portdb =
31 > self.trees[self.settings['EROOT']]['porttree'].dbapi
32 > - proc = AsyncFunction(target=self.sync,
33 > - kwargs=dict(emerge_config=emerge_config,
34 > repo=repo))
35 > - proc.addExitListener(self._sync_callback)
36 > - return proc
37 > + return
38 > SyncRepo(sync_task=AsyncFunction(target=self.sync,
39 > + kwargs=dict(emerge_config=emerge_config,
40 > repo=repo)),
41 > + sync_callback=self._sync_callback)
42 >
43 > def sync(self, emerge_config=None, repo=None):
44 > self.callback = None
45 > @@ -343,3 +343,34 @@ class SyncManager(object):
46 > action_metadata(self.settings, self.portdb,
47 > self.emerge_config.opts, porttrees=[repo.location])
48 >
49 > +
50 > +class SyncRepo(CompositeTask):
51 > + """
52 > + Encapsulates a sync operation and the callback which
53 > executes afterwards,
54 > + so both can be considered as a single composite task. This
55 > is useful
56 > + since we don't want to consider a particular repo's sync
57 > operation as
58 > + complete until after the callback has executed (bug 562264).
59 > +
60 > + The kwargs and result properties expose attributes that are
61 > accessed
62 > + by SyncScheduler.
63 > + """
64 > +
65 > + __slots__ = ('sync_task', 'sync_callback')
66 > +
67 > + @property
68 > + def kwargs(self):
69 > + return self.sync_task.kwargs
70 > +
71 > + @property
72 > + def result(self):
73 > + return self.sync_task.result
74 > +
75 > + def _start(self):
76 > + self._start_task(self.sync_task,
77 > self._sync_task_exit) +
78 > + def _sync_task_exit(self, sync_task):
79 > + self._current_task = None
80 > + self.returncode = sync_task.returncode
81 > + self.sync_callback(self.sync_task)
82 > + self._async_wait()
83 > +
84
85 Looks fine. hopefully this is the last one in the sync code.
86
87 --
88 Brian Dolbec <dolsen>