public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/_emirrordist/
Date: Fri, 24 Mar 2017 20:33:40 +0000 (UTC)	[thread overview]
Message-ID: <1490387545.f70db92cba82535c8f65d385bd08a40207e24ec1.zmedico@gentoo> (raw)

commit:     f70db92cba82535c8f65d385bd08a40207e24ec1
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 21 23:34:18 2017 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Mar 24 20:32:25 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f70db92c

FetchIterator: add terminate method

Add a terminate method to FetchIterator so that it doesn't
delay termination of emirrordist via SIGINT. Otherwise it
it is possible for the __iter__ method to loop for a very
long time after SIGINT has been delivered. For example,
this could happen if there are many ebuilds with stale
cache and RESTRICT=mirror. This issue was discovered
during testing of changes to the MirrorDistTask.terminate
implementation.

 pym/portage/_emirrordist/FetchIterator.py  | 21 +++++++++++++++++++++
 pym/portage/_emirrordist/MirrorDistTask.py |  6 +++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/pym/portage/_emirrordist/FetchIterator.py b/pym/portage/_emirrordist/FetchIterator.py
index 16a0b04c9..38419799d 100644
--- a/pym/portage/_emirrordist/FetchIterator.py
+++ b/pym/portage/_emirrordist/FetchIterator.py
@@ -1,6 +1,8 @@
 # Copyright 2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import threading
+
 from portage import os
 from portage.checksum import (_apply_hash_filter,
 	_filter_unaccelarated_hashes, _hash_filter)
@@ -13,6 +15,19 @@ class FetchIterator(object):
 	def __init__(self, config):
 		self._config = config
 		self._log_failure = config.log_failure
+		self._terminated = threading.Event()
+
+	def terminate(self):
+		"""
+		Schedules early termination of the __iter__ method, which is
+		useful because under some conditions it's possible for __iter__
+		to loop for a long time without yielding to the caller. For
+		example, it's useful when there are many ebuilds with stale
+		cache and RESTRICT=mirror.
+
+		This method is thread-safe (and safe for signal handlers).
+		"""
+		self._terminated.set()
 
 	def _iter_every_cp(self):
 		# List categories individually, in order to start yielding quicker,
@@ -37,6 +52,9 @@ class FetchIterator(object):
 
 		for cp in self._iter_every_cp():
 
+			if self._terminated.is_set():
+				return
+
 			for tree in portdb.porttrees:
 
 				# Reset state so the Manifest is pulled once
@@ -46,6 +64,9 @@ class FetchIterator(object):
 
 				for cpv in portdb.cp_list(cp, mytree=tree):
 
+					if self._terminated.is_set():
+						return
+
 					try:
 						restrict, = portdb.aux_get(cpv, ("RESTRICT",),
 							mytree=tree)

diff --git a/pym/portage/_emirrordist/MirrorDistTask.py b/pym/portage/_emirrordist/MirrorDistTask.py
index d6b3decc0..a34f2c061 100644
--- a/pym/portage/_emirrordist/MirrorDistTask.py
+++ b/pym/portage/_emirrordist/MirrorDistTask.py
@@ -32,9 +32,11 @@ class MirrorDistTask(CompositeTask):
 		self._config = config
 		self._term_rlock = threading.RLock()
 		self._term_callback_handle = None
+		self._fetch_iterator = None
 
 	def _start(self):
-		fetch = TaskScheduler(iter(FetchIterator(self._config)),
+		self._fetch_iterator = FetchIterator(self._config)
+		fetch = TaskScheduler(iter(self._fetch_iterator),
 			max_jobs=self._config.options.jobs,
 			max_load=self._config.options.load_average,
 			event_loop=self._config.event_loop)
@@ -226,6 +228,8 @@ class MirrorDistTask(CompositeTask):
 					self._term_callback)
 
 	def _term_callback(self):
+		if self._fetch_iterator is not None:
+			self._fetch_iterator.terminate()
 		self.cancel()
 		self.wait()
 


             reply	other threads:[~2017-03-24 20:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 20:33 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-04-28 23:08 [gentoo-commits] proj/portage:master commit in: pym/portage/_emirrordist/ Zac Medico
2018-04-28 21:57 Zac Medico
2018-04-28 14:01 Zac Medico
2018-04-26  8:46 Zac Medico
2018-04-25  7:30 Zac Medico
2017-03-24 20:33 Zac Medico
2016-01-07 16:50 Zac Medico
2014-02-02  3:15 Arfrever Frehtes Taifersar Arahesis
2013-08-12 23:09 Zac Medico
2013-08-02 23:27 Zac Medico
2013-06-20  1:23 Zac Medico
2013-01-10 10:35 Zac Medico
2013-01-10  9:40 Zac Medico
2013-01-10  9:18 Zac Medico
2013-01-10  9:05 Zac Medico
2013-01-10  8:41 Zac Medico
2013-01-10  7:54 Zac Medico
2013-01-10  3:57 Zac Medico
2013-01-09 22:23 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1490387545.f70db92cba82535c8f65d385bd08a40207e24ec1.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox