diff options
-rw-r--r-- | pym/_emerge/PollScheduler.py | 33 | ||||
-rw-r--r-- | pym/_emerge/Scheduler.py | 6 |
2 files changed, 27 insertions, 12 deletions
diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index ab18f0d9a..9ddcd96cc 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -1,4 +1,4 @@ -# Copyright 1999-2011 Gentoo Foundation +# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import gzip @@ -24,7 +24,7 @@ from _emerge.PollSelectAdapter import PollSelectAdapter class PollScheduler(object): class _sched_iface_class(SlotObject): - __slots__ = ("idle_add", "io_add_watch", + __slots__ = ("idle_add", "io_add_watch", "iteration", "output", "register", "schedule", "source_remove", "timeout_add", "unregister") @@ -59,6 +59,7 @@ class PollScheduler(object): self.sched_iface = self._sched_iface_class( idle_add=self._idle_add, io_add_watch=self._register, + iteration=self._iteration, output=self._task_output, register=self._register, schedule=self._schedule_wait, @@ -268,14 +269,24 @@ class PollScheduler(object): if not event_handled: raise AssertionError("tight loop") - def _schedule_yield(self): + def _iteration(self, *args): """ - Schedule for a short period of time chosen by the scheduler based - on internal state. Synchronous tasks should call this periodically - in order to allow the scheduler to service pending poll events. The - scheduler will call poll() exactly once, without blocking, and any - resulting poll events will be serviced. + Like glib.MainContext.iteration(), runs a single iteration. + @type may_block: bool + @param may_block: if True the call may block waiting for an event + (default is True). + @rtype: bool + @return: True if events were dispatched. """ + + may_block = True + + if args: + if len(args) > 1: + raise TypeError( + "expected at most 1 argument (%s given)" % len(args)) + may_block = args[0] + event_handlers = self._poll_event_handlers events_handled = 0 @@ -283,7 +294,11 @@ class PollScheduler(object): return bool(events_handled) if not self._poll_event_queue: - self._poll(0) + if may_block: + timeout = 0 + else: + timeout = None + self._poll(timeout=timeout) try: while event_handlers and self._poll_event_queue: diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index b6b6586a5..e22ef46ba 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -1,4 +1,4 @@ -# Copyright 1999-2011 Gentoo Foundation +# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from __future__ import print_function @@ -81,7 +81,7 @@ class Scheduler(PollScheduler): class _iface_class(PollScheduler._sched_iface_class): __slots__ = ("fetch", - "scheduleSetup", "scheduleUnpack", "scheduleYield") + "scheduleSetup", "scheduleUnpack") class _fetch_iface_class(SlotObject): __slots__ = ("log_file", "schedule") @@ -221,11 +221,11 @@ class Scheduler(PollScheduler): fetch=fetch_iface, output=self._task_output, idle_add=self._idle_add, io_add_watch=self._register, + iteration=self._iteration, register=self._register, schedule=self._schedule_wait, scheduleSetup=self._schedule_setup, scheduleUnpack=self._schedule_unpack, - scheduleYield=self._schedule_yield, source_remove=self._unregister, timeout_add=self._timeout_add, unregister=self._unregister) |