summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-07-17 10:53:15 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-07-26 10:32:39 -0700
commitf1e225cbb571920bb6d17f6ff15013f2c69c6c6c (patch)
treeb8ef381eb82a6ad7cf75143610a47808e3d9ddea
parentb19d58f556932eec92e3cf27f6c018791415367d (diff)
Use twisted reactor as asyncio event loop
This puts the twisted event loop into the asyncio framework. This means that we're currently running all over our twisted.defered's and twisted.inlineCallbacks through asyncio, using the twisted loop. This will allow incremental updates from twisted's event loop to a standard asyncio event loop.
-rw-r--r--alot/__main__.py3
-rw-r--r--alot/ui.py12
2 files changed, 10 insertions, 5 deletions
diff --git a/alot/__main__.py b/alot/__main__.py
index 221e6b22..9899bf36 100644
--- a/alot/__main__.py
+++ b/alot/__main__.py
@@ -6,6 +6,9 @@ import logging
import os
import sys
+from twisted.internet import asyncioreactor
+asyncioreactor.install()
+
import alot
from alot.settings.const import settings
from alot.settings.errors import ConfigError
diff --git a/alot/ui.py b/alot/ui.py
index b7490d03..f4b0dc3a 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -6,8 +6,9 @@ import os
import signal
import codecs
import contextlib
+import asyncio
-from twisted.internet import reactor, defer, task
+from twisted.internet import defer, task
import urwid
from .settings.const import settings
@@ -105,7 +106,7 @@ class UI(object):
self.mainloop = urwid.MainLoop(
self.root_widget,
handle_mouse=settings.get('handle_mouse'),
- event_loop=urwid.TwistedEventLoop(),
+ event_loop=urwid.AsyncioEventLoop(),
unhandled_input=self._unhandled_input,
input_filter=self._input_filter)
@@ -359,10 +360,11 @@ class UI(object):
"""
exit_msg = None
try:
- reactor.stop()
+ loop = asyncio.get_event_loop()
+ loop.stop()
except Exception as e:
- exit_msg = 'Could not stop reactor: {}.'.format(e)
- logging.error('%s\nShutting down anyway..', exit_msg)
+ logging.error('Could not stop loop: %s\nShutting down anyway..',
+ str(e))
@contextlib.contextmanager
def paused(self):