Fix shutdown of networkmanager

This commit is contained in:
Florian Bruhin 2014-05-06 10:53:38 +02:00
parent 74b42eaa93
commit de7c6a63b4
3 changed files with 29 additions and 23 deletions

2
TODO
View File

@ -110,6 +110,8 @@ Major features
Minor features Minor features
============== ==============
- Enable disk caching
QNetworkManager.setCache() and use a QNetworkDiskCache probably
- clear cookies - clear cookies
- keybind/aliases should have completion for commands/arguments - keybind/aliases should have completion for commands/arguments
- Hiding scrollbars - Hiding scrollbars

View File

@ -20,9 +20,9 @@
import os import os
import sys import sys
import logging import logging
import functools
import subprocess import subprocess
import configparser import configparser
from functools import partial
from signal import signal, SIGINT from signal import signal, SIGINT
from argparse import ArgumentParser from argparse import ArgumentParser
from base64 import b64encode from base64 import b64encode
@ -102,7 +102,11 @@ class QuteBrowser(QApplication):
def __init__(self): def __init__(self):
super().__init__(sys.argv) super().__init__(sys.argv)
self._quit_status = {} self._quit_status = {
'crash': True,
'tabs': False,
'networkmanager': False
}
self._timers = [] self._timers = []
self._opened_urls = [] self._opened_urls = []
self._shutting_down = False self._shutting_down = False
@ -392,6 +396,8 @@ class QuteBrowser(QApplication):
exc = (exctype, excvalue, tb) exc = (exctype, excvalue, tb)
sys.__excepthook__(*exc) sys.__excepthook__(*exc)
self._quit_status['crash'] = False
if not issubclass(exctype, Exception): if not issubclass(exctype, Exception):
# probably a KeyboardInterrupt # probably a KeyboardInterrupt
try: try:
@ -399,8 +405,6 @@ class QuteBrowser(QApplication):
return return
except Exception: except Exception:
self.quit() self.quit()
self._quit_status['crash'] = False
self._quit_status['shutdown'] = False
try: try:
pages = self._recover_pages() pages = self._recover_pages()
except Exception: except Exception:
@ -483,49 +487,55 @@ class QuteBrowser(QApplication):
@pyqtSlot() @pyqtSlot()
@cmdutils.register(instance='', name=['quit', 'q'], nargs=0) @cmdutils.register(instance='', name=['quit', 'q'], nargs=0)
def shutdown(self, do_quit=True): def shutdown(self):
"""Try to shutdown everything cleanly. """Try to shutdown everything cleanly.
For some reason lastWindowClosing sometimes seem to get emitted twice, For some reason lastWindowClosing sometimes seem to get emitted twice,
so we make sure we only run once here. so we make sure we only run once here.
Args:
do_quit: Whether to quit after shutting down.
""" """
if self._shutting_down: if self._shutting_down:
return return
self._shutting_down = True self._shutting_down = True
logging.debug("Shutting down... (do_quit={})".format(do_quit)) logging.debug("Shutting down...")
# Save config
if self.config.get('general', 'auto-save-config'): if self.config.get('general', 'auto-save-config'):
try: try:
self.config.save() self.config.save()
except AttributeError: except AttributeError:
logging.exception("Could not save config.") logging.exception("Could not save config.")
# Save command history
try: try:
self.cmd_history.save() self.cmd_history.save()
except AttributeError: except AttributeError:
logging.exception("Could not save command history.") logging.exception("Could not save command history.")
# Save window state
try: try:
self._save_geometry() self._save_geometry()
self.stateconfig.save() self.stateconfig.save()
except AttributeError: except AttributeError:
logging.exception("Could not save window geometry.") logging.exception("Could not save window geometry.")
# Save cookies
try: try:
self.cookiejar.save() self.cookiejar.save()
except AttributeError: except AttributeError:
logging.exception("Could not save cookies.") logging.exception("Could not save cookies.")
# Shut down tabs
try: try:
if do_quit: self.mainwindow.tabs.shutdown_complete.connect(partial(
self.mainwindow.tabs.shutdown_complete.connect( self._maybe_quit, 'tabs'))
self.on_tab_shutdown_complete)
else:
self.mainwindow.tabs.shutdown_complete.connect(
functools.partial(self._maybe_quit, 'shutdown'))
self.mainwindow.tabs.shutdown() self.mainwindow.tabs.shutdown()
except AttributeError: # mainwindow or tabs could still be None except AttributeError: # mainwindow or tabs could still be None
logging.exception("No mainwindow/tabs to shut down.") logging.exception("No mainwindow/tabs to shut down.")
if do_quit: self._maybe_quit('tabs')
self.quit() # Shut down networkmanager
try:
self.networkmanager.abort_requests()
self.networkmanager.destroyed.connect(partial(
self._maybe_quit, 'networkmanager'))
self.networkmanager.deleteLater()
except AttributeError:
logging.exception("No networkmanager to shut down.")
self._maybe_quit('networkmanager')
@pyqtSlot() @pyqtSlot()
def on_tab_shutdown_complete(self): def on_tab_shutdown_complete(self):

View File

@ -208,12 +208,6 @@ class WebView(QWebView):
self._destroyed[self] = False self._destroyed[self] = False
self.destroyed.connect(functools.partial(self._on_destroyed, self)) self.destroyed.connect(functools.partial(self._on_destroyed, self))
self.deleteLater() self.deleteLater()
netman = QApplication.instance().networkmanager
self._destroyed[netman] = False
netman.abort_requests()
netman.destroyed.connect(functools.partial(self._on_destroyed, netman))
netman.deleteLater()
logging.debug("Tab shutdown scheduled") logging.debug("Tab shutdown scheduled")
@pyqtSlot(str) @pyqtSlot(str)