MCPcopy Create free account
hub / github.com/ipython/ipython / safe_run_module

Method safe_run_module

IPython/core/interactiveshell.py:2822–2848  ·  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

2820 warn('Unknown failure executing file: <%s>' % fname)
2821
2822 def safe_run_module(self, mod_name, where):
2823 """A safe version of runpy.run_module().
2824
2825 This version will never throw an exception, but instead print
2826 helpful error messages to the screen.
2827
2828 `SystemExit` exceptions with status code 0 or None are ignored.
2829
2830 Parameters
2831 ----------
2832 mod_name : string
2833 The name of the module to be executed.
2834 where : dict
2835 The globals namespace.
2836 """
2837 try:
2838 try:
2839 where.update(
2840 runpy.run_module(str(mod_name), run_name="__main__",
2841 alter_sys=True)
2842 )
2843 except SystemExit as status:
2844 if status.code:
2845 raise
2846 except:
2847 self.showtraceback()
2848 warn('Unknown failure executing module: <%s>' % mod_name)
2849
2850 def run_cell(self, raw_cell, store_history=False, silent=False, shell_futures=True):
2851 """Run a complete IPython cell.

Callers 2

_run_moduleMethod · 0.80
runMethod · 0.80

Calls 2

showtracebackMethod · 0.95
updateMethod · 0.45

Tested by

no test coverage detected