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