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.61878e4fbdfef5f8512b34640089e954a14e6d12.zmedico@gentoo> (raw)

commit:     61878e4fbdfef5f8512b34640089e954a14e6d12
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 21 07:06:12 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=61878e4f

MirrorDistTask: terminate via call_soon for asyncio compat

These changes are analogous to the PollScheduler changes in
the previous commit.

 pym/portage/_emirrordist/MirrorDistTask.py | 39 +++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/pym/portage/_emirrordist/MirrorDistTask.py b/pym/portage/_emirrordist/MirrorDistTask.py
index e23a11b3c..d6b3decc0 100644
--- a/pym/portage/_emirrordist/MirrorDistTask.py
+++ b/pym/portage/_emirrordist/MirrorDistTask.py
@@ -24,15 +24,16 @@ if sys.hexversion >= 0x3000000:
 
 class MirrorDistTask(CompositeTask):
 
-	__slots__ = ('_config', '_terminated', '_term_check_id')
+	__slots__ = ('_config', '_fetch_iterator', '_term_rlock',
+		'_term_callback_handle')
 
 	def __init__(self, config):
 		CompositeTask.__init__(self, scheduler=config.event_loop)
 		self._config = config
-		self._terminated = threading.Event()
+		self._term_rlock = threading.RLock()
+		self._term_callback_handle = None
 
 	def _start(self):
-		self._term_check_id = self.scheduler.idle_add(self._termination_check)
 		fetch = TaskScheduler(iter(FetchIterator(self._config)),
 			max_jobs=self._config.options.jobs,
 			max_load=self._config.options.load_average,
@@ -203,17 +204,31 @@ class MirrorDistTask(CompositeTask):
 		logging.info("added %i files" % added_file_count)
 		logging.info("added %i bytes total" % added_byte_count)
 
+	def _cleanup(self):
+		"""
+		Cleanup any callbacks that have been registered with the global
+		event loop.
+		"""
+		# The self._term_callback_handle attribute requires locking
+		# since it's modified by the thread safe terminate method.
+		with self._term_rlock:
+			if self._term_callback_handle not in (None, False):
+				self._term_callback_handle.cancel()
+			# This prevents the terminate method from scheduling
+			# any more callbacks (since _cleanup must eliminate all
+			# callbacks in order to ensure complete cleanup).
+			self._term_callback_handle = False
+
 	def terminate(self):
-		self._terminated.set()
+		with self._term_rlock:
+			if self._term_callback_handle is None:
+				self._term_callback_handle = self.scheduler.call_soon_threadsafe(
+					self._term_callback)
 
-	def _termination_check(self):
-		if self._terminated.is_set():
-			self.cancel()
-			self.wait()
-		return True
+	def _term_callback(self):
+		self.cancel()
+		self.wait()
 
 	def _wait(self):
 		CompositeTask._wait(self)
-		if self._term_check_id is not None:
-			self.scheduler.source_remove(self._term_check_id)
-			self._term_check_id = None
+		self._cleanup()


             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.61878e4fbdfef5f8512b34640089e954a14e6d12.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