[pygobject/benzea/gio-asyncio: 1/2] fixup! events: Implement asyncio event loop based on glib




commit 6c3607417dfcb096904600b069662a4c8ba50dc2
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Nov 19 10:09:46 2021 +0100

    fixup! events: Implement asyncio event loop based on glib

 gi/events.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/gi/events.py b/gi/events.py
index 8067cf05..c3bb53d1 100644
--- a/gi/events.py
+++ b/gi/events.py
@@ -196,6 +196,12 @@ class GLibEventLoop(asyncio.SelectorEventLoop):
             # Pass over to python mainloop
             self.call_soon(cb, *args)
 
+    def __repr__(self):
+        return (
+            f'<{self.__class__.__name__} running={self.is_running()} '
+            f'closed={self.is_closed()} debug={self.get_debug()} '
+            f'ctx={hash(self._context)} c_obj={hash(self)}>'
+        )
 
 class GLibEventLoopPolicy(events.AbstractEventLoopPolicy):
     """An asyncio event loop policy that runs the GLib main loop.
@@ -246,7 +252,9 @@ class GLibEventLoopPolicy(events.AbstractEventLoopPolicy):
         #       return a new python wrapper. But, we can use hash() as that returns
         #       the pointer to the C structure.
         try:
-            return self._loops[ctx]
+            loop = self._loops[ctx]
+            if not loop.is_closed():
+               return loop
         except KeyError:
             pass
 
@@ -326,6 +334,8 @@ class _Source(GLib.Source):
     def __init__(self, selector):
         super().__init__()
 
+        self._dispatching = False
+
         # It is *not* safe to run the *python* part of the mainloop recursively.
         # (This is the default, but make it explicit.)
         self.set_can_recurse(False)
@@ -403,7 +413,6 @@ class _Selector(selectors.BaseSelector):
 
         self._context = context
         self._loop = loop
-        self._dispatching = False
         self._fd_to_key = {}
 
         self._source = _Source(self)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]