diff --git a/requirements.txt b/requirements.txt index 69562f77..5dfdd319 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ nose-cov nose flake8 python3-parted +tornado diff --git a/subiquity/async.py b/subiquity/async.py index 04450c45..b34ba01f 100644 --- a/subiquity/async.py +++ b/subiquity/async.py @@ -17,30 +17,27 @@ Provides async operations for various api calls and other non-blocking work. -The way this works is you create your IO/CPU bound thread: +The way this works is you create your non-blocking thread: .. code:: def my_async_method(self): pool.submit(func, *args) - # In your controller you would then call + # In your controller you would then call using coroutines - my_async_method_f = my_async_method() - my_async_method_f.add_done_callback(self.handle_async_method) - - def handle_async_method(self, future): + @coroutine + def do_async_action(self): try: - result = future.result() - except Exception as e: - raise Exception("Program in thread {}".format(e)) - + yield my_async_method() + # Move to next coroutine or return if finish + self.do_second_async_action() + except Exeception as e: + log.exception("Failed in our non-blocking code.") """ -from multiprocessing import cpu_count -from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor +from concurrent.futures import ThreadPoolExecutor class Async: - pool = ThreadPoolExecutor(10) - ppool = ProcessPoolExecutor(cpu_count()) + pool = ThreadPoolExecutor(4) diff --git a/subiquity/core.py b/subiquity/core.py index 5b96a901..f717dfc6 100644 --- a/subiquity/core.py +++ b/subiquity/core.py @@ -16,6 +16,7 @@ import logging import urwid import urwid.curses_display +from tornado.ioloop import IOLoop from subiquity.signals import Signal from subiquity.palette import STYLES, STYLES_MONO @@ -102,8 +103,10 @@ class Controller: additional_opts['screen'].set_terminal_properties(colors=256) additional_opts['screen'].reset_default_terminal_palette() + evl = urwid.TornadoEventLoop(IOLoop()) self.loop = urwid.MainLoop( - self.ui, palette, **additional_opts) + self.ui, palette, event_loop=evl, **additional_opts) + log.debug("Running event loop: {}".format(self.loop.event_loop)) try: self.set_alarm_in(0.05, self.welcome)