Internal method to run a complete IPython cell.
(
self,
raw_cell: str,
store_history: bool,
silent: bool,
shell_futures: bool,
cell_id: str,
)
| 3177 | return result |
| 3178 | |
| 3179 | def _run_cell( |
| 3180 | self, |
| 3181 | raw_cell: str, |
| 3182 | store_history: bool, |
| 3183 | silent: bool, |
| 3184 | shell_futures: bool, |
| 3185 | cell_id: str, |
| 3186 | ) -> ExecutionResult: |
| 3187 | """Internal method to run a complete IPython cell.""" |
| 3188 | |
| 3189 | # we need to avoid calling self.transform_cell multiple time on the same thing |
| 3190 | # so we need to store some results: |
| 3191 | preprocessing_exc_tuple = None |
| 3192 | try: |
| 3193 | transformed_cell = self.transform_cell(raw_cell) |
| 3194 | except Exception: |
| 3195 | transformed_cell = raw_cell |
| 3196 | preprocessing_exc_tuple = sys.exc_info() |
| 3197 | |
| 3198 | assert transformed_cell is not None |
| 3199 | coro = self.run_cell_async( |
| 3200 | raw_cell, |
| 3201 | store_history=store_history, |
| 3202 | silent=silent, |
| 3203 | shell_futures=shell_futures, |
| 3204 | transformed_cell=transformed_cell, |
| 3205 | preprocessing_exc_tuple=preprocessing_exc_tuple, |
| 3206 | cell_id=cell_id, |
| 3207 | ) |
| 3208 | |
| 3209 | # run_cell_async is async, but may not actually need an eventloop. |
| 3210 | # when this is the case, we want to run it using the pseudo_sync_runner |
| 3211 | # so that code can invoke eventloops (for example via the %run , and |
| 3212 | # `%paste` magic. |
| 3213 | if self.trio_runner: |
| 3214 | runner = self.trio_runner |
| 3215 | elif self.should_run_async( |
| 3216 | raw_cell, |
| 3217 | transformed_cell=transformed_cell, |
| 3218 | preprocessing_exc_tuple=preprocessing_exc_tuple, |
| 3219 | ): |
| 3220 | runner = self.loop_runner |
| 3221 | else: |
| 3222 | runner = _pseudo_sync_runner |
| 3223 | |
| 3224 | try: |
| 3225 | result = runner(coro) |
| 3226 | except BaseException as e: |
| 3227 | try: |
| 3228 | info = ExecutionInfo( |
| 3229 | raw_cell, |
| 3230 | store_history, |
| 3231 | silent, |
| 3232 | shell_futures, |
| 3233 | cell_id, |
| 3234 | transformed_cell=transformed_cell, |
| 3235 | ) |
| 3236 | result = ExecutionResult(info) |
no test coverage detected