1 |
On Thu, 23 Mar 2017 19:55:00 -0700 |
2 |
Zac Medico <zmedico@g.o> wrote: |
3 |
|
4 |
> Add a terminate method to FetchIterator so that it doesn't |
5 |
> delay termination of emirrordist via SIGINT. Otherwise it |
6 |
> it is possible for the __iter__ method to loop for a very |
7 |
> long time after SIGINT has been delivered. For example, |
8 |
> this could happen if there are many ebuilds with stale |
9 |
> cache and RESTRICT=mirror. This issue was discovered |
10 |
> during testing of changes to the MirrorDistTask.terminate |
11 |
> implementation. |
12 |
> --- |
13 |
> pym/portage/_emirrordist/FetchIterator.py | 21 +++++++++++++++++++++ |
14 |
> pym/portage/_emirrordist/MirrorDistTask.py | 6 +++++- |
15 |
> 2 files changed, 26 insertions(+), 1 deletion(-) |
16 |
> |
17 |
> diff --git a/pym/portage/_emirrordist/FetchIterator.py |
18 |
> b/pym/portage/_emirrordist/FetchIterator.py index 16a0b04..3841979 |
19 |
> 100644 --- a/pym/portage/_emirrordist/FetchIterator.py |
20 |
> +++ b/pym/portage/_emirrordist/FetchIterator.py |
21 |
> @@ -1,6 +1,8 @@ |
22 |
> # Copyright 2013 Gentoo Foundation |
23 |
> # Distributed under the terms of the GNU General Public License v2 |
24 |
> |
25 |
> +import threading |
26 |
> + |
27 |
> from portage import os |
28 |
> from portage.checksum import (_apply_hash_filter, |
29 |
> _filter_unaccelarated_hashes, _hash_filter) |
30 |
> @@ -13,6 +15,19 @@ class FetchIterator(object): |
31 |
> def __init__(self, config): |
32 |
> self._config = config |
33 |
> self._log_failure = config.log_failure |
34 |
> + self._terminated = threading.Event() |
35 |
> + |
36 |
> + def terminate(self): |
37 |
> + """ |
38 |
> + Schedules early termination of the __iter__ method, |
39 |
> which is |
40 |
> + useful because under some conditions it's possible |
41 |
> for __iter__ |
42 |
> + to loop for a long time without yielding to the |
43 |
> caller. For |
44 |
> + example, it's useful when there are many ebuilds |
45 |
> with stale |
46 |
> + cache and RESTRICT=mirror. |
47 |
> + |
48 |
> + This method is thread-safe (and safe for signal |
49 |
> handlers). |
50 |
> + """ |
51 |
> + self._terminated.set() |
52 |
> |
53 |
> def _iter_every_cp(self): |
54 |
> # List categories individually, in order to start |
55 |
> yielding quicker, @@ -37,6 +52,9 @@ class FetchIterator(object): |
56 |
> |
57 |
> for cp in self._iter_every_cp(): |
58 |
> |
59 |
> + if self._terminated.is_set(): |
60 |
> + return |
61 |
> + |
62 |
> for tree in portdb.porttrees: |
63 |
> |
64 |
> # Reset state so the Manifest is |
65 |
> pulled once @@ -46,6 +64,9 @@ class FetchIterator(object): |
66 |
> |
67 |
> for cpv in portdb.cp_list(cp, |
68 |
> mytree=tree): |
69 |
> + if self._terminated.is_set(): |
70 |
> + return |
71 |
> + |
72 |
> try: |
73 |
> restrict, = |
74 |
> portdb.aux_get(cpv, ("RESTRICT",), mytree=tree) |
75 |
> diff --git a/pym/portage/_emirrordist/MirrorDistTask.py |
76 |
> b/pym/portage/_emirrordist/MirrorDistTask.py index 0702eb1..8da9f06 |
77 |
> 100644 --- a/pym/portage/_emirrordist/MirrorDistTask.py |
78 |
> +++ b/pym/portage/_emirrordist/MirrorDistTask.py |
79 |
> @@ -32,9 +32,11 @@ class MirrorDistTask(CompositeTask): |
80 |
> self._config = config |
81 |
> self._term_rlock = threading.RLock() |
82 |
> self._term_callback_handle = None |
83 |
> + self._fetch_iterator = None |
84 |
> |
85 |
> def _start(self): |
86 |
> - fetch = |
87 |
> TaskScheduler(iter(FetchIterator(self._config)), |
88 |
> + self._fetch_iterator = FetchIterator(self._config) |
89 |
> + fetch = TaskScheduler(iter(self._fetch_iterator), |
90 |
> max_jobs=self._config.options.jobs, |
91 |
> max_load=self._config.options.load_average, |
92 |
> event_loop=self._config.event_loop) |
93 |
> @@ -226,6 +228,8 @@ class MirrorDistTask(CompositeTask): |
94 |
> self._term_callback) |
95 |
> |
96 |
> def _term_callback(self): |
97 |
> + if self._fetch_iterator is not None: |
98 |
> + self._fetch_iterator.terminate() |
99 |
> self.cancel() |
100 |
> self.wait() |
101 |
> |
102 |
|
103 |
|
104 |
Not that I know enough about all this that I could say "your doing it |
105 |
wrong" |
106 |
|
107 |
But the series looks OK, I didn't see any obvious goofs ;) |
108 |
|
109 |
Thanks |
110 |
|
111 |
-- |
112 |
Brian Dolbec <dolsen> |