Skip to content

Commit 1d3261d

Browse files
committed
automatically restart kernel in colab
1 parent ba6d509 commit 1d3261d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

examples/virtual_staining/vcp_tutorials/quick_start.ipynb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,18 @@
124124
]
125125
},
126126
{
127-
"cell_type": "markdown",
128-
"id": "2ae23986",
129-
"metadata": {
130-
"cell_marker": "\"\"\""
131-
},
127+
"cell_type": "code",
128+
"execution_count": null,
129+
"id": "f0f20186",
130+
"metadata": {},
131+
"outputs": [],
132132
"source": [
133-
"<div class=\"alert alert-warning\">\n",
134-
"On Google Colab, please restart the session after installing dependencies.\n",
135-
"Click 'Runtime -> Restart session' in the header bar\n",
136-
"or press <kbd>⌘</kbd>/<kbd>Ctrl</kbd> + <kbd>m</kbd> <kbd>.</kbd>.\n",
137-
"</div>"
133+
"# restart kernel if running in Google Colab\n",
134+
"if \"get_ipython\" in globals():\n",
135+
" session = get_ipython()\n",
136+
" if \"google.colab\" in str(session):\n",
137+
" print(\"Shutting down colab session.\")\n",
138+
" session.kernel.do_shutdown(restart=True)"
138139
]
139140
},
140141
{

examples/virtual_staining/vcp_tutorials/quick_start.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,13 @@
9090
# See the [repository](https://github.com/mehta-lab/VisCy) for more details
9191
# !pip install "viscy[metrics,visual]==0.3.0rc3"
9292

93-
# %% [markdown]
94-
"""
95-
<div class="alert alert-warning">
96-
On Google Colab, please restart the session after installing dependencies.
97-
Click 'Runtime -> Restart session' in the header bar
98-
or press <kbd>⌘</kbd>/<kbd>Ctrl</kbd> + <kbd>m</kbd> <kbd>.</kbd>.
99-
</div>
100-
"""
93+
# %%
94+
# restart kernel if running in Google Colab
95+
if "get_ipython" in globals():
96+
session = get_ipython()
97+
if "google.colab" in str(session):
98+
print("Shutting down colab session.")
99+
session.kernel.do_shutdown(restart=True)
101100

102101
# %%
103102
# Validate installation

0 commit comments

Comments
 (0)