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

Method should_run_async

IPython/core/interactiveshell.py:2931–2972  ·  view source on GitHub ↗

Return whether a cell should be run asynchronously via a coroutine runner Parameters ---------- raw_cell: str The code to be executed Returns ------- result: bool Whether the code needs to be run with a coroutine runner or not

(
        self, raw_cell: str, *, transformed_cell=None, preprocessing_exc_tuple=None
    )

Source from the content-addressed store, hash-verified

2929 return
2930
2931 def should_run_async(
2932 self, raw_cell: str, *, transformed_cell=None, preprocessing_exc_tuple=None
2933 ) -> bool:
2934 """Return whether a cell should be run asynchronously via a coroutine runner
2935
2936 Parameters
2937 ----------
2938 raw_cell: str
2939 The code to be executed
2940
2941 Returns
2942 -------
2943 result: bool
2944 Whether the code needs to be run with a coroutine runner or not
2945
2946 .. versionadded: 7.0
2947 """
2948 if not self.autoawait:
2949 return False
2950 if preprocessing_exc_tuple is not None:
2951 return False
2952 assert preprocessing_exc_tuple is None
2953 if transformed_cell is None:
2954 warnings.warn(
2955 "`should_run_async` will not call `transform_cell`"
2956 " automatically in the future. Please pass the result to"
2957 " `transformed_cell` argument and any exception that happen"
2958 " during the"
2959 "transform in `preprocessing_exc_tuple` in"
2960 " IPython 7.17 and above.",
2961 DeprecationWarning,
2962 stacklevel=2,
2963 )
2964 try:
2965 cell = self.transform_cell(raw_cell)
2966 except Exception:
2967 # any exception during transform will be raised
2968 # prior to execution
2969 return False
2970 else:
2971 cell = transformed_cell
2972 return _should_be_async(cell)
2973
2974 async def run_cell_async(
2975 self,

Callers 2

_run_cellMethod · 0.95
test_should_run_asyncFunction · 0.80

Calls 3

transform_cellMethod · 0.95
_should_be_asyncFunction · 0.85
warnMethod · 0.80

Tested by 1

test_should_run_asyncFunction · 0.64