Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion asyncio_glib/glib_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ class GLibEventLoop(asyncio.SelectorEventLoop):
def __init__(self, main_context=None):
if main_context is None:
main_context = GLib.MainContext.default()
selector = glib_selector.GLibSelector(main_context)
self._main_loop = GLib.MainLoop.new(main_context, False)
selector = glib_selector.GLibSelector(main_context, self._main_loop)
super().__init__(selector)

def call_soon(self, *args, **kwargs):
if self._main_loop.is_running():
self._main_loop.quit()
return super().call_soon(*args, **kwargs)

def call_at(self, *args, **kwargs):
if self._main_loop.is_running():
self._main_loop.quit()
return super().call_at(*args, **kwargs)


class GLibEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
"""An asyncio event loop policy that runs the GLib main loop"""
Expand Down
4 changes: 2 additions & 2 deletions asyncio_glib/glib_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def clear(self):

class GLibSelector(selectors._BaseSelectorImpl):

def __init__(self, context):
def __init__(self, context, main_loop):
super().__init__()
self._context = context
self._main_loop = GLib.MainLoop.new(self._context, False)
self._main_loop = main_loop
self._source = _SelectorSource(self._main_loop)
self._source.attach(self._context)

Expand Down
4 changes: 3 additions & 1 deletion tests/test_glib_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
class GLibSelectorTests(test_selectors.BaseSelectorTestCase):

def SELECTOR(self):
return glib_selector.GLibSelector(GLib.MainContext.default())
main_context = GLib.MainContext.default()
main_loop = GLib.MainLoop.new(main_context, False)
return glib_selector.GLibSelector(main_context, main_loop)

def test_select_interrupt_exc(self):
raise unittest.SkipTest("TODO")