MCPcopy Index your code
hub / github.com/ipython/ipython / safe_run_module

Method safe_run_module

IPython/core/interactiveshell.py:3058–3084  ·  view source on GitHub ↗

A safe version of runpy.run_module(). This version will never throw an exception, but instead print helpful error messages to the screen. `SystemExit` exceptions with status code 0 or None are ignored. Parameters ---------- mod_name : string

(self, mod_name, where)

Source from the content-addressed store, hash-verified

3056 warn('Unknown failure executing file: <%s>' % fname)
3057
3058 def safe_run_module(self, mod_name, where):
3059 """A safe version of runpy.run_module().
3060
3061 This version will never throw an exception, but instead print
3062 helpful error messages to the screen.
3063
3064 `SystemExit` exceptions with status code 0 or None are ignored.
3065
3066 Parameters
3067 ----------
3068 mod_name : string
3069 The name of the module to be executed.
3070 where : dict
3071 The globals namespace.
3072 """
3073 try:
3074 try:
3075 where.update(
3076 runpy.run_module(str(mod_name), run_name="__main__",
3077 alter_sys=True)
3078 )
3079 except SystemExit as status:
3080 if status.code:
3081 raise
3082 except:
3083 self.showtraceback()
3084 warn('Unknown failure executing module: <%s>' % mod_name)
3085
3086 @contextmanager
3087 def _tee(self, channel: Literal["stdout", "stderr"]):

Callers 2

_run_moduleMethod · 0.80
runMethod · 0.80

Calls 2

showtracebackMethod · 0.95
updateMethod · 0.45

Tested by

no test coverage detected