diff --git a/qutebrowser/utils/utilcmds.py b/qutebrowser/utils/utilcmds.py index e3083ebf9..5ba6c4bdf 100644 --- a/qutebrowser/utils/utilcmds.py +++ b/qutebrowser/utils/utilcmds.py @@ -37,22 +37,26 @@ def later(ms: int, *command, win_id): ms: How many milliseconds to wait. *command: The command to run, with optional args. """ - app = objreg.get('app') - timer = usertypes.Timer(name='later', parent=app) - timer.setSingleShot(True) if ms < 0: raise cmdexc.CommandError("I can't run something in the past!") - try: - timer.setInterval(ms) - except OverflowError: - raise cmdexc.CommandError("Numeric argument is too large for internal " - "int representation.") cmdline = ' '.join(command) commandrunner = runners.CommandRunner(win_id) - timer.timeout.connect( - functools.partial(commandrunner.run_safely, cmdline)) - timer.timeout.connect(timer.deleteLater) - timer.start() + app = objreg.get('app') + timer = usertypes.Timer(name='later', parent=app) + try: + timer.setSingleShot(True) + try: + timer.setInterval(ms) + except OverflowError: + raise cmdexc.CommandError("Numeric argument is too large for " + "internal int representation.") + timer.timeout.connect( + functools.partial(commandrunner.run_safely, cmdline)) + timer.timeout.connect(timer.deleteLater) + timer.start() + except: # pylint: disable=bare-except + timer.deleteLater() + raise @cmdutils.register(scope='window')