kill off run_in_bg and some related hacks

This commit is contained in:
Michael Hudson-Doyle 2019-12-13 12:24:54 +13:00
parent a92b88ed9d
commit ae5cd6268a
4 changed files with 1 additions and 36 deletions

View File

@ -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

View File

@ -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

View File

@ -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, {})

View File

@ -13,7 +13,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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 = {}