Skip to content

Commit 0373c44

Browse files
committed
python: Added stop_execution() function that allows debugging with printing and just giving up.
1 parent afeff7d commit 0373c44

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

python/inet/common/util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
STDOUT_LEVEL = 25 # between INFO (20) and WARNING (30)
2828
STDERR_LEVEL = 35 # between WARNING (30) and ERROR (40)
2929

30+
class StopExecutionException(Exception):
31+
pass
32+
33+
class TerminalInteractiveShell(IPython.terminal.interactiveshell.TerminalInteractiveShell):
34+
def _showtraceback(self, etype, evalue, stb):
35+
if isinstance(evalue, StopExecutionException):
36+
_logger.warning("Execution stopped programmatically by calling stop_execution()")
37+
return None
38+
super()._showtraceback(etype, evalue, stb)
39+
40+
def stop_execution():
41+
raise StopExecutionException()
42+
3043
def enable_autoreload():
3144
ipython = IPython.get_ipython()
3245
ipython.magic("load_ext autoreload")

python/inet/repl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from omnetpp.scave.analysis import *
77
from omnetpp.scave.results import *
88

9+
from inet.common import *
910
from inet.project.omnetpp import *
1011
from inet.simulation import *
1112
from inet.test import *
@@ -38,6 +39,7 @@ def run_repl_main():
3839
else:
3940
_logger.info("OMNeT++ Python support is loaded.")
4041
app = IPython.terminal.ipapp.TerminalIPythonApp.instance()
42+
app.interactive_shell_class = TerminalInteractiveShell
4143
app.display_banner = False
4244
app.exec_lines = ["from inet import *", "enable_autoreload()", "register_key_bindings()"]
4345
app.initialize(argv=[])

0 commit comments

Comments
 (0)