From cfb29a7cd442b3b6a969561d0d27f52d5c2dba78 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 20 Jan 2021 13:17:51 +0100 Subject: ui: clean up asyncio calls Bump python dependency to 3.7, which added create_task(). --- alot/ui.py | 15 ++++++--------- setup.py | 3 +-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/alot/ui.py b/alot/ui.py index 550ca150..b8bcae5f 100644 --- a/alot/ui.py +++ b/alot/ui.py @@ -259,8 +259,7 @@ class UI: clear() logging.debug("cmdline: '%s'", cmdline) if not self._locked: - loop = asyncio.get_event_loop() - loop.create_task(_apply_fire(cmdline)) + self._loop.create_task(_apply_fire(cmdline)) # move keys are always passed elif cmdline in ['move up', 'move down', 'move page up', 'move page down']: @@ -378,7 +377,7 @@ class UI: """ history = history or [] - fut = asyncio.get_event_loop().create_future() + fut = self._loop.create_future() oldroot = self.mainloop.widget def select_or_cancel(text): @@ -424,15 +423,13 @@ class UI: self._passall = True return fut - @staticmethod - def exit(): + def exit(self): """ shuts down user interface without cleaning up. Use a :class:`alot.commands.globals.ExitCommand` for a clean shutdown. """ try: - loop = asyncio.get_event_loop() - loop.stop() + self._loop.stop() except Exception as e: logging.error('Could not stop loop: %s\nShutting down anyway..', str(e)) @@ -586,7 +583,7 @@ class UI: assert cancel is None or cancel in choices.values() assert msg_position in ['left', 'above'] - fut = asyncio.get_event_loop().create_future() # Create a returned future + fut = self._loop.create_future() oldroot = self.mainloop.widget def select_or_cancel(text): @@ -745,7 +742,7 @@ class UI: # it is a SIGINT ? if signum == signal.SIGINT: logging.info('shut down cleanly') - asyncio.ensure_future(self.apply_command(globals.ExitCommand())) + asyncio.create_task(self.apply_command(globals.ExitCommand())) elif signum == signal.SIGUSR1: if isinstance(self.current_buffer, SearchBuffer): self.current_buffer.rebuild() diff --git a/setup.py b/setup.py index fbeb79f5..56b9f894 100755 --- a/setup.py +++ b/setup.py @@ -21,7 +21,6 @@ setup( 'License :: OSI Approved' ':: GNU General Public License v3 or later (GPLv3+)'), 'Operating System :: POSIX', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3 :: Only', 'Topic :: Communications :: Email :: Email Clients (MUA)', @@ -53,5 +52,5 @@ setup( ], provides=['alot'], test_suite="tests", - python_requires=">=3.6", + python_requires=">=3.7", ) -- cgit v1.2.3