commit:     608663259a8a6fa78c32205389dfa58d00b6f11c
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 15 18:56:43 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Apr 15 18:58:00 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=60866325

Implement AbstractEventLoop.is_running() (bug 649588)

Bug: https://bugs.gentoo.org/649588

 pym/portage/util/_eventloop/EventLoop.py | 14 ++++++++++++++
 pym/portage/util/futures/unix_events.py  |  1 +
 2 files changed, 15 insertions(+)

diff --git a/pym/portage/util/_eventloop/EventLoop.py 
b/pym/portage/util/_eventloop/EventLoop.py
index 13ce5478e..a928f3138 100644
--- a/pym/portage/util/_eventloop/EventLoop.py
+++ b/pym/portage/util/_eventloop/EventLoop.py
@@ -125,6 +125,10 @@ class EventLoop(object):
                self._poll_event_queue = []
                self._poll_event_handlers = {}
                self._poll_event_handler_ids = {}
+               # Number of current calls to self.iteration(). A number greater
+               # than 1 indicates recursion, which is not supported by 
asyncio's
+               # default event loop.
+               self._iteration_depth = 0
                # Increment id for each new handler.
                self._event_handler_id = 0
                # New call_soon callbacks must have an opportunity to
@@ -262,7 +266,13 @@ class EventLoop(object):
                @rtype: bool
                @return: True if events were dispatched.
                """
+               self._iteration_depth += 1
+               try:
+                       return self._iteration(*args)
+               finally:
+                       self._iteration_depth -= 1
 
+       def _iteration(self, *args):
                may_block = True
 
                if args:
@@ -822,6 +832,10 @@ class EventLoop(object):
                                self._default_executor = executor
                return executor.submit(func, *args)
 
+       def is_running(self):
+               """Return whether the event loop is currently running."""
+               return self._iteration_depth > 0
+
        def is_closed(self):
                """Returns True if the event loop was closed."""
                return self._poll_obj is None

diff --git a/pym/portage/util/futures/unix_events.py 
b/pym/portage/util/futures/unix_events.py
index 1abc420e1..d788c2bea 100644
--- a/pym/portage/util/futures/unix_events.py
+++ b/pym/portage/util/futures/unix_events.py
@@ -43,6 +43,7 @@ class _PortageEventLoop(events.AbstractEventLoop):
                self.call_soon_threadsafe = loop.call_soon_threadsafe
                self.call_later = loop.call_later
                self.call_at = loop.call_at
+               self.is_running = loop.is_running
                self.is_closed = loop.is_closed
                self.close = loop.close
                self.create_future = loop.create_future

Reply via email to