Fix urwid stalling until input received

fixes #364
This commit is contained in:
Ivan Habunek 2023-12-19 11:08:52 +01:00
parent 561506ee2d
commit d9c6bf79c8
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
1 changed files with 6 additions and 3 deletions

View File

@ -172,8 +172,8 @@ class TUI(urwid.Frame):
return urwid.Filler(intro)
def run_in_thread(self, fn, args=[], kwargs={}, done_callback=None, error_callback=None):
"""Runs `fn(*args, **kwargs)` asynchronously in a separate thread.
def run_in_thread(self, fn, done_callback=None, error_callback=None):
"""Runs `fn` asynchronously in a separate thread.
On completion calls `done_callback` if `fn` exited cleanly, or
`error_callback` if an exception was caught. Callback methods are
@ -197,7 +197,10 @@ class TUI(urwid.Frame):
logger.exception(exception)
self.loop.set_alarm_in(0, lambda *args: _error_callback(exception))
future = self.executor.submit(fn, *args, **kwargs)
# TODO: replace by `self.loop.event_loop.run_in_executor` at some point
# Added in https://github.com/urwid/urwid/issues/575
# Not yet released at the time of this comment
future = self.loop.event_loop._loop.run_in_executor(self.executor, fn)
future.add_done_callback(_done)
return future