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

Method run_code

IPython/core/interactiveshell.py:3712–3773  ·  view source on GitHub ↗

Execute a code object. When an exception occurs, self.showtraceback() is called to display a traceback. Parameters ---------- code_obj : code object A compiled code object, to be executed result : ExecutionResult, optional An obje

(self, code_obj, result=None, *, async_=False)

Source from the content-addressed store, hash-verified

3710 return False
3711
3712 async def run_code(self, code_obj, result=None, *, async_=False):
3713 """Execute a code object.
3714
3715 When an exception occurs, self.showtraceback() is called to display a
3716 traceback.
3717
3718 Parameters
3719 ----------
3720 code_obj : code object
3721 A compiled code object, to be executed
3722 result : ExecutionResult, optional
3723 An object to store exceptions that occur during execution.
3724 async_ : Bool (Experimental)
3725 Attempt to run top-level asynchronous code in a default loop.
3726
3727 Returns
3728 -------
3729 False : successful execution.
3730 True : an error occurred.
3731 """
3732 # special value to say that anything above is IPython and should be
3733 # hidden.
3734 __tracebackhide__ = "__ipython_bottom__"
3735 # Set our own excepthook in case the user code tries to call it
3736 # directly, so that the IPython crash handler doesn't get triggered
3737 old_excepthook, sys.excepthook = sys.excepthook, self.excepthook
3738
3739 # we save the original sys.excepthook in the instance, in case config
3740 # code (such as magics) needs access to it.
3741 self.sys_excepthook = old_excepthook
3742 outflag = True # happens in more places, so it's easier as default
3743 try:
3744 try:
3745 if async_:
3746 await eval(code_obj, self.user_global_ns, self.user_ns)
3747 else:
3748 exec(code_obj, self.user_global_ns, self.user_ns)
3749 finally:
3750 # Reset our crash handler in place
3751 sys.excepthook = old_excepthook
3752 except SystemExit as e:
3753 if result is not None:
3754 result.error_in_exec = e
3755 self.showtraceback(exception_only=True)
3756 warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
3757 except bdb.BdbQuit:
3758 etype, value, tb = sys.exc_info()
3759 if result is not None:
3760 result.error_in_exec = value
3761 # the BdbQuit stops here
3762 except self.custom_exceptions:
3763 etype, value, tb = sys.exc_info()
3764 if result is not None:
3765 result.error_in_exec = value
3766 self.CustomTB(etype, value, tb)
3767 except:
3768 if result is not None:
3769 result.error_in_exec = sys.exc_info()[1]

Callers 1

run_ast_nodesMethod · 0.95

Calls 1

showtracebackMethod · 0.95

Tested by

no test coverage detected