From 50ac03eacb300a49a50340a1443dc63a3590b35c Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 7 Dec 2022 14:59:26 +1300 Subject: [PATCH] Remove Application.aio_loop attribute --- subiquity/ui/views/installprogress.py | 5 +++-- subiquity/ui/views/refresh.py | 4 +++- subiquity/ui/views/tests/test_installprogress.py | 1 - subiquitycore/core.py | 4 ++-- subiquitycore/tui.py | 9 +++++---- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/subiquity/ui/views/installprogress.py b/subiquity/ui/views/installprogress.py index 931b46c8..88c48157 100644 --- a/subiquity/ui/views/installprogress.py +++ b/subiquity/ui/views/installprogress.py @@ -289,7 +289,7 @@ class InstallRunning(Stretchy): self.btn = Toggleable(other_btn( _("Switch to a shell"), on_press=self._debug_shell)) self.btn.enabled = False - self.app.aio_loop.call_later(0.5, self._enable) + self._enable_task = asyncio.create_task(self._enable()) widgets = [ Text(rewrap(_(running_text).format(tty=tty))), Text(''), @@ -301,7 +301,8 @@ class InstallRunning(Stretchy): stretchy_index=0, focus_index=2) - def _enable(self): + async def _enable(self): + await asyncio.sleep(0.5) self.btn.enabled = True def _debug_shell(self, sender): diff --git a/subiquity/ui/views/refresh.py b/subiquity/ui/views/refresh.py index ccd0abfa..6b40f685 100644 --- a/subiquity/ui/views/refresh.py +++ b/subiquity/ui/views/refresh.py @@ -228,7 +228,9 @@ class RefreshView(BaseView): if self.controller.answers['update']: self.update() else: - self.controller.app.aio_loop.call_soon(self.skip_update) + async def skip(): + self.skip_update() + self._skip_task = asyncio.create_task(skip()) def update(self, sender=None): self.spinner.stop() diff --git a/subiquity/ui/views/tests/test_installprogress.py b/subiquity/ui/views/tests/test_installprogress.py index ad06c5db..64b374e0 100644 --- a/subiquity/ui/views/tests/test_installprogress.py +++ b/subiquity/ui/views/tests/test_installprogress.py @@ -13,7 +13,6 @@ class IdentityViewTests(unittest.TestCase): def make_view(self): controller = mock.create_autospec(spec=ProgressController) controller.app = mock.Mock() - controller.app.aio_loop = None return ProgressView(controller) def test_initial_focus(self): diff --git a/subiquitycore/core.py b/subiquitycore/core.py index 8bbd08eb..d783f2c1 100644 --- a/subiquitycore/core.py +++ b/subiquitycore/core.py @@ -70,8 +70,8 @@ class Application: os.environ.get('SUBIQUITY_REPLAY_TIMESCALE', "1")) self.updated = os.path.exists(self.state_path('updating')) self.hub = MessageHub() - self.aio_loop = asyncio.get_running_loop() - self.aio_loop.set_exception_handler(self._exception_handler) + asyncio.get_running_loop().set_exception_handler( + self._exception_handler) self.load_controllers(self.controllers) self.context = Context.new(self) self.exit_event = asyncio.Event() diff --git a/subiquitycore/tui.py b/subiquitycore/tui.py index 7a433fde..c607e02b 100644 --- a/subiquitycore/tui.py +++ b/subiquitycore/tui.py @@ -154,7 +154,8 @@ class TuiApplication(Application): """ min_show_task = None - def _show(): + async def _show(): + await asyncio.sleep(MAX_BLOCK_TIME) self.ui.block_input = False nonlocal min_show_task min_show_task = asyncio.create_task( @@ -162,7 +163,7 @@ class TuiApplication(Application): show() self.ui.block_input = True - show_handle = self.aio_loop.call_later(MAX_BLOCK_TIME, _show) + show_task = asyncio.create_task(_show()) try: result = await awaitable finally: @@ -172,7 +173,7 @@ class TuiApplication(Application): hide() else: self.ui.block_input = False - show_handle.cancel() + show_task.cancel() return result @@ -296,7 +297,7 @@ class TuiApplication(Application): self.ui, screen=screen, handle_mouse=False, pop_ups=True, unhandled_input=self.unhandled_input, - event_loop=urwid.AsyncioEventLoop(loop=self.aio_loop), + event_loop=urwid.AsyncioEventLoop(loop=asyncio.get_running_loop()), **self.extra_urwid_loop_args() ) extend_dec_special_charmap()