Remove ipc-server from objreg
This commit is contained in:
parent
ce0622e38a
commit
b906c862bb
@ -638,10 +638,16 @@ class Quitter:
|
|||||||
log.destroy.debug("sys.path: {}".format(sys.path))
|
log.destroy.debug("sys.path: {}".format(sys.path))
|
||||||
log.destroy.debug("sys.argv: {}".format(sys.argv))
|
log.destroy.debug("sys.argv: {}".format(sys.argv))
|
||||||
log.destroy.debug("frozen: {}".format(hasattr(sys, 'frozen')))
|
log.destroy.debug("frozen: {}".format(hasattr(sys, 'frozen')))
|
||||||
|
|
||||||
# Save the session if one is given.
|
# Save the session if one is given.
|
||||||
if session is not None:
|
if session is not None:
|
||||||
session_manager = objreg.get('session-manager')
|
session_manager = objreg.get('session-manager')
|
||||||
session_manager.save(session, with_private=True)
|
session_manager.save(session, with_private=True)
|
||||||
|
|
||||||
|
# Make sure we're not accepting a connection from the new process before
|
||||||
|
# we fully exited.
|
||||||
|
ipc.server.shutdown()
|
||||||
|
|
||||||
# Open a new process and immediately shutdown the existing one
|
# Open a new process and immediately shutdown the existing one
|
||||||
try:
|
try:
|
||||||
args, cwd = self._get_restart_args(pages, session, override_args)
|
args, cwd = self._get_restart_args(pages, session, override_args)
|
||||||
@ -732,7 +738,7 @@ class Quitter:
|
|||||||
QApplication.closeAllWindows()
|
QApplication.closeAllWindows()
|
||||||
# Shut down IPC
|
# Shut down IPC
|
||||||
try:
|
try:
|
||||||
objreg.get('ipc-server').shutdown()
|
ipc.server.shutdown()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
# Save everything
|
# Save everything
|
||||||
|
@ -39,7 +39,7 @@ from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QObject,
|
|||||||
from PyQt5.QtWidgets import QApplication, QDialog
|
from PyQt5.QtWidgets import QApplication, QDialog
|
||||||
|
|
||||||
from qutebrowser.commands import cmdutils
|
from qutebrowser.commands import cmdutils
|
||||||
from qutebrowser.misc import earlyinit, crashdialog
|
from qutebrowser.misc import earlyinit, crashdialog, ipc
|
||||||
from qutebrowser.utils import usertypes, standarddir, log, objreg, debug, utils
|
from qutebrowser.utils import usertypes, standarddir, log, objreg, debug, utils
|
||||||
|
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ class CrashHandler(QObject):
|
|||||||
info = self._get_exception_info()
|
info = self._get_exception_info()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
objreg.get('ipc-server').ignored = True
|
ipc.server.ignored = True
|
||||||
except Exception:
|
except Exception:
|
||||||
log.destroy.exception("Error while ignoring ipc")
|
log.destroy.exception("Error while ignoring ipc")
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, Qt
|
|||||||
from PyQt5.QtNetwork import QLocalSocket, QLocalServer, QAbstractSocket
|
from PyQt5.QtNetwork import QLocalSocket, QLocalServer, QAbstractSocket
|
||||||
|
|
||||||
import qutebrowser
|
import qutebrowser
|
||||||
from qutebrowser.utils import log, usertypes, error, objreg, standarddir, utils
|
from qutebrowser.utils import log, usertypes, error, standarddir, utils
|
||||||
|
|
||||||
|
|
||||||
CONNECT_TIMEOUT = 100 # timeout for connecting/disconnecting
|
CONNECT_TIMEOUT = 100 # timeout for connecting/disconnecting
|
||||||
@ -40,6 +40,10 @@ ATIME_INTERVAL = 60 * 60 * 3 * 1000 # 3 hours
|
|||||||
PROTOCOL_VERSION = 1
|
PROTOCOL_VERSION = 1
|
||||||
|
|
||||||
|
|
||||||
|
# The ipc server instance
|
||||||
|
server = None
|
||||||
|
|
||||||
|
|
||||||
def _get_socketname_windows(basedir):
|
def _get_socketname_windows(basedir):
|
||||||
"""Get a socketname to use for Windows."""
|
"""Get a socketname to use for Windows."""
|
||||||
parts = ['qutebrowser', getpass.getuser()]
|
parts = ['qutebrowser', getpass.getuser()]
|
||||||
@ -482,6 +486,7 @@ def send_or_listen(args):
|
|||||||
The IPCServer instance if no running instance was detected.
|
The IPCServer instance if no running instance was detected.
|
||||||
None if an instance was running and received our request.
|
None if an instance was running and received our request.
|
||||||
"""
|
"""
|
||||||
|
global server
|
||||||
socketname = _get_socketname(args.basedir)
|
socketname = _get_socketname(args.basedir)
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
@ -492,7 +497,6 @@ def send_or_listen(args):
|
|||||||
log.init.debug("Starting IPC server...")
|
log.init.debug("Starting IPC server...")
|
||||||
server = IPCServer(socketname)
|
server = IPCServer(socketname)
|
||||||
server.listen()
|
server.listen()
|
||||||
objreg.register('ipc-server', server)
|
|
||||||
return server
|
return server
|
||||||
except AddressInUseError as e:
|
except AddressInUseError as e:
|
||||||
# This could be a race condition...
|
# This could be a race condition...
|
||||||
|
@ -34,7 +34,7 @@ from PyQt5.QtTest import QSignalSpy
|
|||||||
|
|
||||||
import qutebrowser
|
import qutebrowser
|
||||||
from qutebrowser.misc import ipc
|
from qutebrowser.misc import ipc
|
||||||
from qutebrowser.utils import objreg, standarddir, utils
|
from qutebrowser.utils import standarddir, utils
|
||||||
from helpers import stubs
|
from helpers import stubs
|
||||||
|
|
||||||
|
|
||||||
@ -45,12 +45,8 @@ pytestmark = pytest.mark.usefixtures('qapp')
|
|||||||
def shutdown_server():
|
def shutdown_server():
|
||||||
"""If ipc.send_or_listen was called, make sure to shut server down."""
|
"""If ipc.send_or_listen was called, make sure to shut server down."""
|
||||||
yield
|
yield
|
||||||
try:
|
if ipc.server is not None:
|
||||||
server = objreg.get('ipc-server')
|
ipc.server.shutdown()
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
server.shutdown()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -609,13 +605,6 @@ class TestSendOrListen:
|
|||||||
return self.Args(no_err_windows=True, basedir='/basedir/for/testing',
|
return self.Args(no_err_windows=True, basedir='/basedir/for/testing',
|
||||||
command=['test'], target=None)
|
command=['test'], target=None)
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def cleanup(self):
|
|
||||||
try:
|
|
||||||
objreg.delete('ipc-server')
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def qlocalserver_mock(self, mocker):
|
def qlocalserver_mock(self, mocker):
|
||||||
m = mocker.patch('qutebrowser.misc.ipc.QLocalServer', autospec=True)
|
m = mocker.patch('qutebrowser.misc.ipc.QLocalServer', autospec=True)
|
||||||
@ -639,8 +628,7 @@ class TestSendOrListen:
|
|||||||
assert isinstance(ret_server, ipc.IPCServer)
|
assert isinstance(ret_server, ipc.IPCServer)
|
||||||
msgs = [e.message for e in caplog.records]
|
msgs = [e.message for e in caplog.records]
|
||||||
assert "Starting IPC server..." in msgs
|
assert "Starting IPC server..." in msgs
|
||||||
objreg_server = objreg.get('ipc-server')
|
assert ret_server is ipc.server
|
||||||
assert objreg_server is ret_server
|
|
||||||
|
|
||||||
with qtbot.waitSignal(ret_server.got_args):
|
with qtbot.waitSignal(ret_server.got_args):
|
||||||
ret_client = ipc.send_or_listen(args)
|
ret_client = ipc.send_or_listen(args)
|
||||||
|
Loading…
Reference in New Issue
Block a user