Browse Source

qt gui: some more clean-up when exiting

related: https://github.com/spesmilo/electrum/issues/6889

This fixes the case where the user quits by pressing Ctrl+C,
and some other minor things.

There is still another issue that sometimes causes a segfault during shutdown...
patch-4
SomberNight 4 years ago
parent
commit
34e64ef152
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 5
      electrum/gui/qt/__init__.py
  2. 20
      electrum/gui/qt/main_window.py
  3. 16
      electrum/gui/qt/network_dialog.py
  4. 2
      electrum/gui/qt/util.py

5
electrum/gui/qt/__init__.py

@ -329,7 +329,7 @@ class ElectrumGui(Logger):
def close_window(self, window: ElectrumWindow):
if window in self.windows:
self.windows.remove(window)
self.windows.remove(window)
self.build_tray_menu()
# save wallet path of last open window
if not self.windows:
@ -375,6 +375,9 @@ class ElectrumGui(Logger):
self.app.lastWindowClosed.connect(quit_after_last_window)
def clean_up():
# If there are still some open windows, try to clean them up.
for window in list(self.windows):
window.clean_up()
# Shut down the timer cleanly
self.timer.stop()
# clipboard persistence. see http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg17328.html

20
electrum/gui/qt/main_window.py

@ -190,7 +190,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.contacts = wallet.contacts
self.tray = gui_object.tray
self.app = gui_object.app
self.cleaned_up = False
self._cleaned_up = False
self.payment_request = None # type: Optional[paymentrequest.PaymentRequest]
self.payto_URI = None
self.checking_accounts = False
@ -300,6 +300,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
_("Would you like to be notified when there is a newer version of Electrum available?"))
config.set_key('check_updates', bool(choice), save=True)
self._update_check_thread = None
if config.get('check_updates', False):
# The references to both the thread and the window need to be stored somewhere
# to prevent GC from getting in our way.
@ -496,7 +497,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def close_wallet(self):
if self.wallet:
self.logger.info(f'close_wallet {self.wallet.storage.path}')
self.wallet.thread = None
run_hook('close_wallet', self.wallet)
@profiler
@ -3158,14 +3158,17 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.show_warning(_('Please restart Electrum to activate the new GUI settings'), title=_('Success'))
def closeEvent(self, event):
# It seems in some rare cases this closeEvent() is called twice
if not self.cleaned_up:
self.cleaned_up = True
self.clean_up()
# note that closeEvent is NOT called if the user quits with Ctrl-C
self.clean_up()
event.accept()
def clean_up(self):
self.wallet.thread.stop()
if self._cleaned_up:
return
self._cleaned_up = True
if self.wallet.thread:
self.wallet.thread.stop()
self.wallet.thread = None
util.unregister_callback(self.on_network)
self.config.set_key("is_maximized", self.isMaximized())
if not self.isMaximized():
@ -3177,6 +3180,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.qr_window.close()
self.close_wallet()
if self._update_check_thread:
self._update_check_thread.exit()
self._update_check_thread.wait()
self.gui_object.timer.timeout.disconnect(self.timer_actions)
self.gui_object.close_window(self)

16
electrum/gui/qt/network_dialog.py

@ -65,6 +65,7 @@ class NetworkDialog(QDialog):
self.network_updated_signal_obj.network_updated_signal.connect(
self.on_update)
util.register_callback(self.on_network, ['network_updated'])
self._cleaned_up = False
def on_network(self, event, *args):
self.network_updated_signal_obj.network_updated_signal.emit(event, args)
@ -72,6 +73,14 @@ class NetworkDialog(QDialog):
def on_update(self):
self.nlayout.update()
def closeEvent(self, event):
if not self._cleaned_up:
self._cleaned_up = True
self.clean_up()
event.accept()
def clean_up(self):
self.nlayout.clean_up()
class NodesListWidget(QTreeWidget):
@ -308,6 +317,13 @@ class NetworkChoiceLayout(object):
self.fill_in_proxy_settings()
self.update()
def clean_up(self):
if self.td:
self.td.found_proxy.disconnect()
self.td.exit()
self.td.wait()
self.td = None
def check_disable_proxy(self, b):
if not self.config.is_modifiable('proxy'):
b = False

2
electrum/gui/qt/util.py

@ -914,6 +914,8 @@ class TaskThread(QThread):
def stop(self):
self.tasks.put(None)
self.exit()
self.wait()
class ColorSchemeItem:

Loading…
Cancel
Save