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

Method _run_cell

IPython/core/interactiveshell.py:2884–2929  ·  view source on GitHub ↗

Internal method to run a complete IPython cell.

(self, raw_cell:str, store_history:bool, silent:bool, shell_futures:bool)

Source from the content-addressed store, hash-verified

2882 return result
2883
2884 def _run_cell(self, raw_cell:str, store_history:bool, silent:bool, shell_futures:bool):
2885 """Internal method to run a complete IPython cell."""
2886
2887 # we need to avoid calling self.transform_cell multiple time on the same thing
2888 # so we need to store some results:
2889 preprocessing_exc_tuple = None
2890 try:
2891 transformed_cell = self.transform_cell(raw_cell)
2892 except Exception:
2893 transformed_cell = raw_cell
2894 preprocessing_exc_tuple = sys.exc_info()
2895
2896 assert transformed_cell is not None
2897 coro = self.run_cell_async(
2898 raw_cell,
2899 store_history=store_history,
2900 silent=silent,
2901 shell_futures=shell_futures,
2902 transformed_cell=transformed_cell,
2903 preprocessing_exc_tuple=preprocessing_exc_tuple,
2904 )
2905
2906 # run_cell_async is async, but may not actually need an eventloop.
2907 # when this is the case, we want to run it using the pseudo_sync_runner
2908 # so that code can invoke eventloops (for example via the %run , and
2909 # `%paste` magic.
2910 if self.trio_runner:
2911 runner = self.trio_runner
2912 elif self.should_run_async(
2913 raw_cell,
2914 transformed_cell=transformed_cell,
2915 preprocessing_exc_tuple=preprocessing_exc_tuple,
2916 ):
2917 runner = self.loop_runner
2918 else:
2919 runner = _pseudo_sync_runner
2920
2921 try:
2922 return runner(coro)
2923 except BaseException as e:
2924 info = ExecutionInfo(raw_cell, store_history, silent, shell_futures)
2925 result = ExecutionResult(info)
2926 result.error_in_exec = e
2927 self.showtraceback(running_compiled_code=True)
2928 return result
2929 return
2930
2931 def should_run_async(
2932 self, raw_cell: str, *, transformed_cell=None, preprocessing_exc_tuple=None

Callers 1

run_cellMethod · 0.95

Calls 6

transform_cellMethod · 0.95
run_cell_asyncMethod · 0.95
should_run_asyncMethod · 0.95
showtracebackMethod · 0.95
ExecutionInfoClass · 0.85
ExecutionResultClass · 0.85

Tested by

no test coverage detected