Queue a cell for execution. Cells created or edited in the same batch are not executed automatically — use `run_cell` to mark them for execution. Can also be used to re-run an existing cell without editing it. All queued `run_cell` targets are executed in a single b
(self, target: str)
| 1301 | ) |
| 1302 | |
| 1303 | def run_cell(self, target: str) -> None: |
| 1304 | """Queue a cell for execution. |
| 1305 | |
| 1306 | Cells created or edited in the same batch are not executed |
| 1307 | automatically — use `run_cell` to mark them for execution. |
| 1308 | Can also be used to re-run an existing cell without editing it. |
| 1309 | |
| 1310 | All queued `run_cell` targets are executed in a single batch |
| 1311 | on context exit, after structural operations (create/edit/delete) |
| 1312 | have been applied. |
| 1313 | |
| 1314 | Examples: |
| 1315 | ```python |
| 1316 | # Create and run |
| 1317 | cid = ctx.create_cell("x = 1") |
| 1318 | ctx.run_cell(cid) |
| 1319 | |
| 1320 | # Edit and run |
| 1321 | ctx.edit_cell("my_cell", code="y = 2") |
| 1322 | ctx.run_cell("my_cell") |
| 1323 | |
| 1324 | # Re-run an existing cell without editing |
| 1325 | ctx.run_cell("my_cell") |
| 1326 | ``` |
| 1327 | |
| 1328 | Args: |
| 1329 | target (str): Cell ID or cell name to execute. |
| 1330 | """ |
| 1331 | self._require_entered() |
| 1332 | cell_id = self._resolve_target(target) |
| 1333 | # Guard against running a cell that is queued for deletion. |
| 1334 | deleted_ids = { |
| 1335 | op.cell_id for op in self._ops if isinstance(op, _DeleteOp) |
| 1336 | } |
| 1337 | if cell_id in deleted_ids: |
| 1338 | raise ValueError( |
| 1339 | f"Cannot run cell {target!r} because it is queued " |
| 1340 | "for deletion in this batch" |
| 1341 | ) |
| 1342 | self._cells_to_run.add(cell_id) |
| 1343 | |
| 1344 | # ------------------------------------------------------------------ |
| 1345 | # Screenshot |