How can I stop a particular cell from running in google colab?

Viewed 24124

If a cell is taking too long to run (for example, if it has code to train the model in deep learning) , how can I stop it from running in Google Colab.

3 Answers

Press the stop button, or select the 'Interrupt execution' item from the Runtime menu.

enter image description here

Keep in mind that some code cannot be interrupted. (For example, if you're using a C library stuck in a syscall.) In these cases, you can restart your Python process by selecting 'Restart runtime...' from the Runtime menu.

If you have a multi-cell file running and you need to stop a particular cell from running. Follow this:

A multicell notebook is running

Select the code from the google colab cell of interest.

Select the code

Use ctrl + x to cut the code from the cell (or copy). Delete the cell (this stops the code from executing).

Delete the cell

Now, create a new cell and paste the code you just copied.

write a code cell 1/0 and this will return an error like this:

This is the trick to stop the code from running past this point.

Now you can RUN ALL of notebook.. or from a particular point.. and code will stop at this error.

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-63-9e1622b385b6> in <module>()
----> 1 1/0

ZeroDivisionError: division by zero
Related