diff --git a/DESIGN.md b/DESIGN.md index 3af5c992..458b4d31 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -164,12 +164,6 @@ running things in the background and subiquity uses [trio](https://trio.readthedocs.io/en/stable/) has nicer APIs but is a bit too new for now. -The older approach which is still present in the codebase is the `run_in_bg` -function, which takes two functions: one that takes no arguments and is called -in a background thread and a callback that takes one argument, and is called -in the main/UI thread with a `concurrent.futures.Future` representing the -result of calling the first function. - A cast-iron rule: Only touch the UI from the main thread. ### Terminal things diff --git a/subiquity/controllers/tests/test_filesystem.py b/subiquity/controllers/tests/test_filesystem.py index 149a60cf..289d9f61 100644 --- a/subiquity/controllers/tests/test_filesystem.py +++ b/subiquity/controllers/tests/test_filesystem.py @@ -34,7 +34,7 @@ class Thing: class MiniApplication: - ui = signal = loop = run_in_bg = None + ui = signal = loop = None answers = {} opts = Thing() opts.dry_run = True diff --git a/subiquitycore/controller.py b/subiquitycore/controller.py index ed09038e..10caa1d7 100644 --- a/subiquitycore/controller.py +++ b/subiquitycore/controller.py @@ -46,7 +46,6 @@ class BaseController(ABC): # subiquity/controllers/installprogress.py self.debug_flags = os.environ.get('SUBIQUITY_DEBUG', '').split(',') self.loop = app.loop - self.run_in_bg = app.run_in_bg self.app = app self.answers = app.answers.get(self.name, {}) diff --git a/subiquitycore/core.py b/subiquitycore/core.py index 9b0bc822..8dddf8ea 100644 --- a/subiquitycore/core.py +++ b/subiquitycore/core.py @@ -13,7 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from concurrent import futures import fcntl import json import logging @@ -373,29 +372,8 @@ class Application: self.signal = Signal() self.prober = prober self.loop = None - self.pool = futures.ThreadPoolExecutor(10) self.controllers = ControllerSet(self, self.controllers) - def run_in_bg(self, func, callback): - """Run func() in a thread and call callback on UI thread. - - callback will be passed a concurrent.futures.Future containing - the result of func(). The result of callback is discarded. An - exception will crash the process so be careful! - """ - fut = self.pool.submit(func) - - def in_main_thread(ignored): - self.loop.remove_watch_pipe(pipe) - os.close(pipe) - callback(fut) - - pipe = self.loop.watch_pipe(in_main_thread) - - def in_random_thread(ignored): - os.write(pipe, b'x') - fut.add_done_callback(in_random_thread) - def run_command_in_foreground(self, cmd, before_hook=None, after_hook=None, **kw): screen = self.loop.screen @@ -652,9 +630,3 @@ class Application: except Exception: log.exception("Exception in controller.run():") raise - finally: - # concurrent.futures.ThreadPoolExecutor tries to join all - # threads before exiting. We don't want that and this - # ghastly hack prevents it. - from concurrent.futures import thread - thread._threads_queues = {}