Browse Source

Qt: add name to coroutines_scheduled

patch-4
ThomasV 3 years ago
parent
commit
2e120d74b8
  1. 22
      electrum/gui/qt/main_window.py
  2. 4
      electrum/gui/qt/swap_dialog.py

22
electrum/gui/qt/main_window.py

@ -206,7 +206,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.current_request = None # request shown in the receive tab self.current_request = None # request shown in the receive tab
Logger.__init__(self) Logger.__init__(self)
self._coroutines_scheduled = set() # type: Set[concurrent.futures.Future] self._coroutines_scheduled = {} # type: Dict[concurrent.futures.Future, str]
self.thread = TaskThread(self, self.on_error) self.thread = TaskThread(self, self.on_error)
self.tx_notification_queue = queue.Queue() self.tx_notification_queue = queue.Queue()
@ -328,7 +328,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self._update_check_thread.checked.connect(on_version_received) self._update_check_thread.checked.connect(on_version_received)
self._update_check_thread.start() self._update_check_thread.start()
def run_coroutine_from_thread(self, coro, on_result=None): def run_coroutine_from_thread(self, coro, name, on_result=None):
if self._cleaned_up: if self._cleaned_up:
self.logger.warning(f"stopping or already stopped but run_coroutine_from_thread was called.") self.logger.warning(f"stopping or already stopped but run_coroutine_from_thread was called.")
return return
@ -342,11 +342,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
if on_result: if on_result:
on_result(res) on_result(res)
finally: finally:
self._coroutines_scheduled.discard(fut) self._coroutines_scheduled.pop(fut)
self.need_update.set() self.need_update.set()
fut = asyncio.run_coroutine_threadsafe(wrapper(), self.network.asyncio_loop) fut = asyncio.run_coroutine_threadsafe(wrapper(), self.network.asyncio_loop)
self._coroutines_scheduled.add(fut) self._coroutines_scheduled[fut] = name
self.need_update.set() self.need_update.set()
def on_fx_history(self): def on_fx_history(self):
@ -1031,7 +1031,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.status_button.setIcon(icon) self.status_button.setIcon(icon)
num_tasks = self.num_tasks() num_tasks = self.num_tasks()
self.tasks_label.setText("(%d %s)"%(num_tasks, _("tasks"))) if num_tasks == 0:
name = ''
elif num_tasks == 1:
name = list(self._coroutines_scheduled.values())[0] + '...'
else:
name = "%d"%num_tasks + _('tasks') + '...'
self.tasks_label.setText(name)
self.tasks_label.setVisible(num_tasks > 0) self.tasks_label.setVisible(num_tasks > 0)
def num_tasks(self): def num_tasks(self):
@ -1813,7 +1819,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return return
self.save_pending_invoice() self.save_pending_invoice()
coro = self.wallet.lnworker.pay_invoice(invoice.lightning_invoice, amount_msat=amount_msat) coro = self.wallet.lnworker.pay_invoice(invoice.lightning_invoice, amount_msat=amount_msat)
self.run_coroutine_from_thread(coro) self.run_coroutine_from_thread(coro, _('Sending payment'))
def run_swap_dialog(self, is_reverse=None, recv_amount_sat=None, channels=None): def run_swap_dialog(self, is_reverse=None, recv_amount_sat=None, channels=None):
if not self.network: if not self.network:
@ -3486,7 +3492,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
if self.thread: if self.thread:
self.thread.stop() self.thread.stop()
self.thread = None self.thread = None
for fut in self._coroutines_scheduled: for fut in self._coroutines_scheduled.keys():
fut.cancel() fut.cancel()
util.unregister_callback(self.on_network) util.unregister_callback(self.on_network)
self.config.set_key("is_maximized", self.isMaximized()) self.config.set_key("is_maximized", self.isMaximized())
@ -3768,5 +3774,5 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
return return
amount_msat = amount_e.get_amount() * 1000 amount_msat = amount_e.get_amount() * 1000
coro = self.wallet.lnworker.rebalance_channels(d.chan_from, d.chan_to, amount_msat=amount_msat) coro = self.wallet.lnworker.rebalance_channels(d.chan_from, d.chan_to, amount_msat=amount_msat)
self.run_coroutine_from_thread(coro) self.run_coroutine_from_thread(coro, _('Rebalancing channels'))
self.update_current_request() self.update_current_request()

4
electrum/gui/qt/swap_dialog.py

@ -231,7 +231,7 @@ class SwapDialog(WindowModalDialog):
lightning_amount_sat=lightning_amount, lightning_amount_sat=lightning_amount,
expected_onchain_amount_sat=onchain_amount + self.swap_manager.get_claim_fee(), expected_onchain_amount_sat=onchain_amount + self.swap_manager.get_claim_fee(),
) )
self.window.run_coroutine_from_thread(coro) self.window.run_coroutine_from_thread(coro, _('Swapping funds'))
return True return True
else: else:
lightning_amount = self.recv_amount_e.get_amount() lightning_amount = self.recv_amount_e.get_amount()
@ -290,7 +290,7 @@ class SwapDialog(WindowModalDialog):
tx=tx, tx=tx,
channels=self.channels, channels=self.channels,
) )
self.window.run_coroutine_from_thread(coro) self.window.run_coroutine_from_thread(coro, _('Swapping funds'))
def get_description(self): def get_description(self):
onchain_funds = "onchain funds" onchain_funds = "onchain funds"

Loading…
Cancel
Save