Skip to content

Commit 5bcd753

Browse files
committed
print-traceback
1 parent ee36bf9 commit 5bcd753

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

IPython/core/magics/execution.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ def timeit(self, line='', cell=None, local_ns=None):
12591259
if return_result:
12601260
return timeit_result
12611261

1262+
@no_var_expand
12621263
@magic_arguments.magic_arguments()
12631264
@magic_arguments.argument(
12641265
"--no-raise-error",
@@ -1267,7 +1268,6 @@ def timeit(self, line='', cell=None, local_ns=None):
12671268
help="If given, don't re-raise exceptions",
12681269
)
12691270
@skip_doctest
1270-
@no_var_expand
12711271
@needs_local_scope
12721272
@line_cell_magic
12731273
@output_can_be_silenced
@@ -1414,15 +1414,18 @@ def __init__(self, no_raise_error):
14141414
# Track whether to propagate exceptions or exit
14151415
exit_on_interrupt = False
14161416
interrupt_occured = False
1417+
captured_exception = None
14171418

14181419
if mode == "eval":
14191420
st = clock2()
14201421
try:
14211422
out = eval(code, glob, local_ns)
1422-
except KeyboardInterrupt:
1423+
except KeyboardInterrupt as e:
1424+
captured_exception = e
14231425
interrupt_occured = True
14241426
exit_on_interrupt = True
1425-
except Exception:
1427+
except Exception as e:
1428+
captured_exception = e
14261429
interrupt_occured = True
14271430
if not args.no_raise_error:
14281431
exit_on_interrupt = True
@@ -1436,10 +1439,12 @@ def __init__(self, no_raise_error):
14361439
if expr_val is not None:
14371440
code_2 = self.shell.compile(expr_val, source, 'eval')
14381441
out = eval(code_2, glob, local_ns)
1439-
except KeyboardInterrupt:
1442+
except KeyboardInterrupt as e:
1443+
captured_exception = e
14401444
interrupt_occured = True
14411445
exit_on_interrupt = True
1442-
except Exception:
1446+
except Exception as e:
1447+
captured_exception = e
14431448
interrupt_occured = True
14441449
if not args.no_raise_error:
14451450
exit_on_interrupt = True
@@ -1463,9 +1468,8 @@ def __init__(self, no_raise_error):
14631468
if tp > tp_min:
14641469
print(f"Parser : {_format_time(tp)}")
14651470
if interrupt_occured:
1466-
if exit_on_interrupt:
1467-
self.shell.showtraceback()
1468-
sys.exit(signal.SIGINT)
1471+
if exit_on_interrupt and captured_exception:
1472+
raise captured_exception
14691473
return
14701474
return out
14711475

0 commit comments

Comments
 (0)