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
)
| 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, |