Skip to content

Commit

Permalink
Update elapsed time, even when exception occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
macevhicz committed Aug 17, 2024
1 parent 63fb0bb commit 0965074
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions preditor/gui/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,27 @@ def executeString(self, commandText, filename='<ConsolePrEdit>', extraPrint=True
# exec which has no Return.
wasEval = False
startTime = time.time()

try:
compiled = compile(commandText, filename, 'eval')
wasEval = True
except Exception:
compiled = compile(commandText, filename, 'exec')
if wasEval:
cmdresult = eval(compiled, __main__.__dict__, __main__.__dict__)
else:
exec(compiled, __main__.__dict__, __main__.__dict__)

# We wrap in try / finally so that elapsed time gets updated, even when an
# exception is raised.
try:
if wasEval:
cmdresult = eval(compiled, __main__.__dict__, __main__.__dict__)
else:
exec(compiled, __main__.__dict__, __main__.__dict__)
finally:
# Report the total time it took to execute this code.
if self.reportExecutionTime is not None:
delta = time.time() - startTime
self.reportExecutionTime((delta, commandText))

# Provide user feedback when running long code execution.
delta = time.time() - startTime
if self.flash_window and self.flash_time and delta >= self.flash_time:
if settings.OS_TYPE == "Windows":
try:
Expand All @@ -420,9 +429,6 @@ def executeString(self, commandText, filename='<ConsolePrEdit>', extraPrint=True
hwnd = int(self.flash_window.winId())
utils.flash_window(hwnd)

# Report the total time it took to execute this code.
if self.reportExecutionTime is not None:
self.reportExecutionTime((delta, commandText))
return cmdresult, wasEval

def executeCommand(self):
Expand Down

0 comments on commit 0965074

Please sign in to comment.