bhatnaushad
bhatnaushad

Reputation: 402

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

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.

Upvotes: 22

Views: 43471

Answers (3)

Ali Akbar Kiaei
Ali Akbar Kiaei

Reputation: 15

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

Upvotes: -1

Iceman_R1331
Iceman_R1331

Reputation: 97

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.

Upvotes: 7

Bob Smith
Bob Smith

Reputation: 38579

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.

Upvotes: 16

Related Questions