* [gentoo-portage-dev] [PATCH] SyncRepos.async: group sync and callback as composite task (bug 562264)
@ 2015-10-05 23:04 Zac Medico
2015-10-06 7:01 ` Brian Dolbec
0 siblings, 1 reply; 2+ messages in thread
From: Zac Medico @ 2015-10-05 23:04 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Zac Medico
Group together the sync operation and the callback as a single task,
so that the callback will not execute concurrently with another sync
operation for --jobs=1.
X-Gentoo-Bug: 562264
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=562264
---
pym/portage/sync/controller.py | 39 +++++++++++++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py
index 28dbc57..159b9c0 100644
--- a/pym/portage/sync/controller.py
+++ b/pym/portage/sync/controller.py
@@ -25,6 +25,7 @@ from portage.util._async.AsyncFunction import AsyncFunction
from portage import OrderedDict
from portage import _unicode_decode
from portage import util
+from _emerge.CompositeTask import CompositeTask
class TaskHandler(object):
@@ -119,10 +120,9 @@ class SyncManager(object):
self.settings, self.trees, self.mtimedb = emerge_config
self.xterm_titles = "notitles" not in self.settings.features
self.portdb = self.trees[self.settings['EROOT']]['porttree'].dbapi
- proc = AsyncFunction(target=self.sync,
- kwargs=dict(emerge_config=emerge_config, repo=repo))
- proc.addExitListener(self._sync_callback)
- return proc
+ return SyncRepo(sync_task=AsyncFunction(target=self.sync,
+ kwargs=dict(emerge_config=emerge_config, repo=repo)),
+ sync_callback=self._sync_callback)
def sync(self, emerge_config=None, repo=None):
self.callback = None
@@ -343,3 +343,34 @@ class SyncManager(object):
action_metadata(self.settings, self.portdb, self.emerge_config.opts,
porttrees=[repo.location])
+
+class SyncRepo(CompositeTask):
+ """
+ Encapsulates a sync operation and the callback which executes afterwards,
+ so both can be considered as a single composite task. This is useful
+ since we don't want to consider a particular repo's sync operation as
+ complete until after the callback has executed (bug 562264).
+
+ The kwargs and result properties expose attributes that are accessed
+ by SyncScheduler.
+ """
+
+ __slots__ = ('sync_task', 'sync_callback')
+
+ @property
+ def kwargs(self):
+ return self.sync_task.kwargs
+
+ @property
+ def result(self):
+ return self.sync_task.result
+
+ def _start(self):
+ self._start_task(self.sync_task, self._sync_task_exit)
+
+ def _sync_task_exit(self, sync_task):
+ self._current_task = None
+ self.returncode = sync_task.returncode
+ self.sync_callback(self.sync_task)
+ self._async_wait()
+
--
2.4.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] SyncRepos.async: group sync and callback as composite task (bug 562264)
2015-10-05 23:04 [gentoo-portage-dev] [PATCH] SyncRepos.async: group sync and callback as composite task (bug 562264) Zac Medico
@ 2015-10-06 7:01 ` Brian Dolbec
0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2015-10-06 7:01 UTC (permalink / raw
To: gentoo-portage-dev
On Mon, 5 Oct 2015 16:04:16 -0700
Zac Medico <zmedico@gentoo.org> wrote:
> Group together the sync operation and the callback as a single task,
> so that the callback will not execute concurrently with another sync
> operation for --jobs=1.
>
> X-Gentoo-Bug: 562264
> X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=562264
> ---
> pym/portage/sync/controller.py | 39
> +++++++++++++++++++++++++++++++++++---- 1 file changed, 35
> insertions(+), 4 deletions(-)
>
> diff --git a/pym/portage/sync/controller.py
> b/pym/portage/sync/controller.py index 28dbc57..159b9c0 100644
> --- a/pym/portage/sync/controller.py
> +++ b/pym/portage/sync/controller.py
> @@ -25,6 +25,7 @@ from portage.util._async.AsyncFunction import
> AsyncFunction from portage import OrderedDict
> from portage import _unicode_decode
> from portage import util
> +from _emerge.CompositeTask import CompositeTask
>
>
> class TaskHandler(object):
> @@ -119,10 +120,9 @@ class SyncManager(object):
> self.settings, self.trees, self.mtimedb =
> emerge_config self.xterm_titles = "notitles" not in
> self.settings.features self.portdb =
> self.trees[self.settings['EROOT']]['porttree'].dbapi
> - proc = AsyncFunction(target=self.sync,
> - kwargs=dict(emerge_config=emerge_config,
> repo=repo))
> - proc.addExitListener(self._sync_callback)
> - return proc
> + return
> SyncRepo(sync_task=AsyncFunction(target=self.sync,
> + kwargs=dict(emerge_config=emerge_config,
> repo=repo)),
> + sync_callback=self._sync_callback)
>
> def sync(self, emerge_config=None, repo=None):
> self.callback = None
> @@ -343,3 +343,34 @@ class SyncManager(object):
> action_metadata(self.settings, self.portdb,
> self.emerge_config.opts, porttrees=[repo.location])
>
> +
> +class SyncRepo(CompositeTask):
> + """
> + Encapsulates a sync operation and the callback which
> executes afterwards,
> + so both can be considered as a single composite task. This
> is useful
> + since we don't want to consider a particular repo's sync
> operation as
> + complete until after the callback has executed (bug 562264).
> +
> + The kwargs and result properties expose attributes that are
> accessed
> + by SyncScheduler.
> + """
> +
> + __slots__ = ('sync_task', 'sync_callback')
> +
> + @property
> + def kwargs(self):
> + return self.sync_task.kwargs
> +
> + @property
> + def result(self):
> + return self.sync_task.result
> +
> + def _start(self):
> + self._start_task(self.sync_task,
> self._sync_task_exit) +
> + def _sync_task_exit(self, sync_task):
> + self._current_task = None
> + self.returncode = sync_task.returncode
> + self.sync_callback(self.sync_task)
> + self._async_wait()
> +
Looks fine. hopefully this is the last one in the sync code.
--
Brian Dolbec <dolsen>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-10-06 7:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-05 23:04 [gentoo-portage-dev] [PATCH] SyncRepos.async: group sync and callback as composite task (bug 562264) Zac Medico
2015-10-06 7:01 ` Brian Dolbec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox