##// END OF EJS Templates
Prevent infinite loops in input transformation
Thomas Kluyver -
Show More
@@ -405,6 +405,9 b' def show_linewise_tokens(s: str):'
405 405 for tokinfo in line:
406 406 print(" ", tokinfo)
407 407
408 # Arbitrary limit to prevent getting stuck in infinite loops
409 TRANSFORM_LOOP_LIMIT = 500
410
408 411 class TransformerManager:
409 412 def __init__(self):
410 413 self.cleanup_transforms = [
@@ -451,11 +454,14 b' class TransformerManager:'
451 454 return True, transformer.transform(lines)
452 455
453 456 def do_token_transforms(self, lines):
454 while True:
457 for _ in range(TRANSFORM_LOOP_LIMIT):
455 458 changed, lines = self.do_one_token_transform(lines)
456 459 if not changed:
457 460 return lines
458 461
462 raise RuntimeError("Input transformation still changing after "
463 "%d iterations. Aborting." % TRANSFORM_LOOP_LIMIT)
464
459 465 def transform_cell(self, cell: str):
460 466 if not cell.endswith('\n'):
461 467 cell += '\n' # Ensure the cell has a trailing newline
General Comments 0
You need to be logged in to leave comments. Login now