Clean up :later timers correctly on exceptions.

This commit is contained in:
Florian Bruhin 2014-10-08 07:52:49 +02:00
parent 50f7067d6c
commit 7956f2b8e2

View File

@ -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!")
cmdline = ' '.join(command)
commandrunner = runners.CommandRunner(win_id)
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.")
cmdline = ' '.join(command)
commandrunner = runners.CommandRunner(win_id)
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')