me2 beats
me2 beats

Reputation: 824

Google Colab - how to restart runtime using code?

I want to restart current runtime (Ctrl+M) using code. Something like:

!restart_runtime

Is there such an option?

Upvotes: 5

Views: 8789

Answers (2)

alex romanoff
alex romanoff

Reputation: 21

You can only delete runtime using this code:

from google.colab import runtime
runtime.unassign()

Place runtime.unassign() command at the end of your script. It will disconnect and delete runtime.

After runtime deleting you should restart this manually or, maybe, using Selenium for automatically browser menu clicking.

Upvotes: 0

Bob Smith
Bob Smith

Reputation: 38579

The runtime process will restart automatically when halted. So, one way to implement restart_runtime would be:

import os

def restart_runtime():
  os.kill(os.getpid(), 9)

Upvotes: 10

Related Questions