More shutdown/crashing improvments.
This commit is contained in:
parent
1dc382e2b7
commit
14a090c087
@ -149,6 +149,27 @@ class QuteBrowser(QApplication):
|
|||||||
for url in config.config.get('general', 'startpage').split(','):
|
for url in config.config.get('general', 'startpage').split(','):
|
||||||
self.mainwindow.tabs.tabopen(url)
|
self.mainwindow.tabs.tabopen(url)
|
||||||
|
|
||||||
|
def _recover_pages(self):
|
||||||
|
"""Try to recover all open pages.
|
||||||
|
|
||||||
|
Return a list of open pages, or an empty list.
|
||||||
|
Called from _exception_hook, so as forgiving as possible.
|
||||||
|
|
||||||
|
"""
|
||||||
|
pages = []
|
||||||
|
if self.mainwindow is None:
|
||||||
|
return pages
|
||||||
|
if self.mainwindow.tabs is None:
|
||||||
|
return pages
|
||||||
|
for tabidx in range(self.mainwindow.tabs.count()):
|
||||||
|
try:
|
||||||
|
url = self.mainwindow.tabs.widget(tabidx).url().toString()
|
||||||
|
if url:
|
||||||
|
pages.append(url)
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
pass
|
||||||
|
return pages
|
||||||
|
|
||||||
def _exception_hook(self, exctype, excvalue, tb):
|
def _exception_hook(self, exctype, excvalue, tb):
|
||||||
"""Handle uncaught python exceptions.
|
"""Handle uncaught python exceptions.
|
||||||
|
|
||||||
@ -161,18 +182,17 @@ class QuteBrowser(QApplication):
|
|||||||
exc = (exctype, excvalue, tb)
|
exc = (exctype, excvalue, tb)
|
||||||
sys.__excepthook__(*exc)
|
sys.__excepthook__(*exc)
|
||||||
|
|
||||||
|
if not (isinstance(exctype, Exception) or exctype is Exception):
|
||||||
|
# probably a KeyboardInterrupt
|
||||||
|
try:
|
||||||
|
self.shutdown()
|
||||||
|
return
|
||||||
|
except Exception:
|
||||||
|
self.quit()
|
||||||
|
try:
|
||||||
|
pages = self._recover_pages()
|
||||||
|
except Exception:
|
||||||
pages = []
|
pages = []
|
||||||
try:
|
|
||||||
for tabidx in range(self.mainwindow.tabs.count()):
|
|
||||||
try:
|
|
||||||
url = self.mainwindow.tabs.widget(tabidx).url().toString()
|
|
||||||
url = url.strip()
|
|
||||||
if url:
|
|
||||||
pages.append(url)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
history = self.mainwindow.status.cmd.history[-5:]
|
history = self.mainwindow.status.cmd.history[-5:]
|
||||||
@ -280,10 +300,15 @@ class QuteBrowser(QApplication):
|
|||||||
if self.shutting_down:
|
if self.shutting_down:
|
||||||
return
|
return
|
||||||
self.shutting_down = True
|
self.shutting_down = True
|
||||||
logging.debug("Shutting down...")
|
logging.debug("Shutting down... (do_quit={})".format(do_quit))
|
||||||
|
if config.config is not None:
|
||||||
config.config.save()
|
config.config.save()
|
||||||
|
try:
|
||||||
|
if do_quit:
|
||||||
self.mainwindow.tabs.shutdown_complete.connect(self.quit)
|
self.mainwindow.tabs.shutdown_complete.connect(self.quit)
|
||||||
self.mainwindow.tabs.shutdown()
|
self.mainwindow.tabs.shutdown()
|
||||||
|
except AttributeError: # mainwindow or tabs could still be None
|
||||||
|
logging.debug("No mainwindow/tabs to shut down.")
|
||||||
if do_quit:
|
if do_quit:
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
|
@ -450,7 +450,13 @@ class TabbedBrowser(TabWidget):
|
|||||||
self.currentChanged.disconnect()
|
self.currentChanged.disconnect()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
for tabidx in range(self.count()):
|
tabcount = self.count()
|
||||||
|
logging.debug("Shutting down {} tabs...".format(tabcount))
|
||||||
|
if tabcount == 0:
|
||||||
|
self.shutdown_complete.emit()
|
||||||
|
return
|
||||||
|
for tabidx in range(tabcount):
|
||||||
|
logging.debug("shutdown {}".format(tabidx))
|
||||||
tab = self.widget(tabidx)
|
tab = self.widget(tabidx)
|
||||||
tab.shutdown(callback=functools.partial(self._cb_tab_shutdown,
|
tab.shutdown(callback=functools.partial(self._cb_tab_shutdown,
|
||||||
tab))
|
tab))
|
||||||
@ -568,6 +574,7 @@ class BrowserTab(QWebView):
|
|||||||
netman.abort_requests()
|
netman.abort_requests()
|
||||||
netman.destroyed.connect(functools.partial(self.on_destroyed, netman))
|
netman.destroyed.connect(functools.partial(self.on_destroyed, netman))
|
||||||
netman.deleteLater()
|
netman.deleteLater()
|
||||||
|
logging.debug("Shutdown scheduled")
|
||||||
|
|
||||||
def on_destroyed(self, sender):
|
def on_destroyed(self, sender):
|
||||||
"""Called when a subsystem has been destroyed during shutdown."""
|
"""Called when a subsystem has been destroyed during shutdown."""
|
||||||
|
Loading…
Reference in New Issue
Block a user