[pygobject/benzea/gio-asyncio] fixup! events: Implement asyncio event loop based on glib
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/benzea/gio-asyncio] fixup! events: Implement asyncio event loop based on glib
- Date: Fri, 19 Nov 2021 13:51:50 +0000 (UTC)
commit b7c4fa2cc1b022423de4a006c06f4caa7db74623
Author: Benjamin Berg <bberg redhat com>
Date: Fri Nov 19 14:49:40 2021 +0100
fixup! events: Implement asyncio event loop based on glib
gi/events.py | 4 ++--
tests/test_events.py | 8 ++++++--
2 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/gi/events.py b/gi/events.py
index 1b219637..76a942b4 100644
--- a/gi/events.py
+++ b/gi/events.py
@@ -200,7 +200,7 @@ class GLibEventLoop(asyncio.SelectorEventLoop):
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)}>'
+ f'ctx=0x{hash(self._context):X} loop=0x{hash(self._main_loop):X}>'
)
class GLibEventLoopPolicy(events.AbstractEventLoopPolicy):
@@ -254,7 +254,7 @@ class GLibEventLoopPolicy(events.AbstractEventLoopPolicy):
try:
loop = self._loops[ctx]
if not loop.is_closed():
- return loop
+ return loop
except KeyError:
pass
diff --git a/tests/test_events.py b/tests/test_events.py
index 394a5430..2809155d 100644
--- a/tests/test_events.py
+++ b/tests/test_events.py
@@ -54,8 +54,8 @@ if sys.platform != 'win32':
# Nop out set_child_watcher to not throw a NotImplemented error
policy.set_child_watcher = lambda *args: None
- # And wrap set_event_loop to only check and unset (but not set),
- # just use an unbound method for the wrapping
+ # Wrap set_event_loop to only check and unset (but not set)
+ # See create_event_loop()
def set_event_loop(loop):
nonlocal policy
nonlocal orig_set_event_loop
@@ -97,6 +97,10 @@ if sys.platform != 'win32':
print('test case tear down done')
def create_event_loop(self):
+ # Aour policy does not support explicitly creating an event loop
+ # that will be used for the main thread.
+ # So, create the loop by fetching it instead.
+ asyncio.get_event_loop_policy().set_event_loop(None)
return asyncio.get_event_loop_policy().get_event_loop()
def test_run_until_complete(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]