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. ms: How many milliseconds to wait.
*command: The command to run, with optional args. *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: if ms < 0:
raise cmdexc.CommandError("I can't run something in the past!") 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: try:
timer.setInterval(ms) timer.setInterval(ms)
except OverflowError: except OverflowError:
raise cmdexc.CommandError("Numeric argument is too large for internal " raise cmdexc.CommandError("Numeric argument is too large for "
"int representation.") "internal int representation.")
cmdline = ' '.join(command)
commandrunner = runners.CommandRunner(win_id)
timer.timeout.connect( timer.timeout.connect(
functools.partial(commandrunner.run_safely, cmdline)) functools.partial(commandrunner.run_safely, cmdline))
timer.timeout.connect(timer.deleteLater) timer.timeout.connect(timer.deleteLater)
timer.start() timer.start()
except: # pylint: disable=bare-except
timer.deleteLater()
raise
@cmdutils.register(scope='window') @cmdutils.register(scope='window')