'Google Colab - Repeat Runtime Disconnect
I've tried to look through Stack Overflow for this issue and wasn't able to find any solutions to my specific situation, which is as follows (fwiw im also a python noob):
**I am using Google Colab (Free).
I'm trying to visualize some data (global temperature) in a radial graph, following a tutorial I found online. Everything seemed to be going decently up until when the final animation was being produced - initially it was fine, with the exception of this warning:
Animation size has reached 22083561 bytes, exceeding the limit of 20971520.0. If you're sure you want a larger animation embedded, set the animation.embed_limit rc parameter to a larger value (in MB). This and further frames will be dropped.
I looked up this information bit/error and found that the following code would increase the limit:
from matplotlib import rcParams
rcParams['animation.embed_limit'] = 2**128
From there, my sessions disconnected around the 1 minute mark after running the appropriate output code. It takes a runtime restart and setting animation.embed_limit to 20 in order for me to get back to my semi-successful state of outputting an incomplete animation.
Any help with this would be greatly appreciated.
Code is as follows
# Drive Mounting
from google.colab import drive
drive.mount('/content/drive')
# Library Imports
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib import rc
rc('animation', html='jshtml')
from matplotlib import rcParams
rcParams['animation.embed_limit'] = 2**128
import numpy as np
# Raw Data Import
hadcrut = pd.read_csv(
'/content/drive/MyDrive/HadCRUT.4.6.0.0.monthly_ns_avg.txt',
delim_whitespace=True,
usecols=[0, 1],
header=None)
# Data Prep
hadcrut['year'] = hadcrut.iloc[:, 0].apply(lambda x: x.split("/")[0]).astype(int)
hadcrut['month'] = hadcrut.iloc[:, 0].apply(lambda x: x.split("/")[1]).astype(int)
hadcrut = hadcrut.rename(columns={1: 'value'})
hadcrut = hadcrut.iloc[:, 1:]
hadcrut = hadcrut.drop(hadcrut[hadcrut['year'] == 2018].index)
hadcrut = hadcrut.set_index(['year', 'month'])
hadcrut -= hadcrut.loc[1850:1900].mean()
hadcrut = hadcrut.reset_index()
years = hadcrut['year'].unique()
fig = plt.figure(figsize=(14,14))
ax1 = plt.subplot(111, projection='polar')
ax1.axes.get_yaxis().set_ticklabels([])
ax1.axes.get_xaxis().set_ticklabels([])
fig.set_facecolor('#323331')
full_circle_thetas = np.linspace(0, 2*np.pi, 1000)
blue_line_one_radii = [1.0]*1000
red_line_one_radii = [2.5]*1000
red_line_two_radii = [3.0]*1000
ax1.plot(full_circle_thetas, blue_line_one_radii, c='blue')
ax1.plot(full_circle_thetas, red_line_one_radii, c='red')
ax1.plot(full_circle_thetas, red_line_two_radii, c='red')
ax1.text(np.pi/2, 1.0, '0.0 C', color='blue', ha='center', fontdict={'fontsize': 20})
ax1.text(np.pi/2, 2.5, '1.5 C', color='red', ha='center', fontdict={'fontsize': 20})
ax1.text(np.pi/2, 3.0, '2.0 C', color='red', ha='center', fontdict={'fontsize': 20})
def update(i):
year = years[i]
r = hadcrut[hadcrut['year'] == year]['value'] + 1
theta = np.linspace(0, 2*np.pi, 12)
ax1.grid(False)
ax1.set_title('Global Temperature Change (1850-2017)', color='white', fontdict={'fontsize': 20})
ax1.set_ylim(0, 3.25)
ax1.set_facecolor('#000100')
ax1.plot(theta, r, c=plt.cm.viridis(i*2))
return ax1
anim = FuncAnimation(fig, update, frames=len(years), interval = 50, repeat_delay = 1000)
anim
And here is the runtime log from restart to disconnect
Timestamp,Level,Message "Apr 16, 2022, 4:18:40 PM",INFO,Discarding 3 buffered messages for d5ff7869-edb3-4e31-a38e-20e2c655f7d2:c7df80dc0b1b4ae7959d1ea88b633edb "Apr 16, 2022, 4:18:40 PM",INFO,Adapting to protocol v5.1 for kernel d5ff7869-edb3-4e31-a38e-20e2c655f7d2 "Apr 16, 2022, 4:18:38 PM",WARNING,tornado.websocket.WebSocketClosedError "Apr 16, 2022, 4:18:38 PM",WARNING, raise WebSocketClosedError() "Apr 16, 2022, 4:18:38 PM",WARNING," File ""/usr/local/lib/python3.7/dist-packages/tornado/websocket.py"", line 876, in wrapper" "Apr 16, 2022, 4:18:38 PM",WARNING, yielded = self.gen.throw(*exc_info) "Apr 16, 2022, 4:18:38 PM",WARNING," File ""/usr/local/lib/python3.7/dist-packages/tornado/gen.py"", line 1141, in run" "Apr 16, 2022, 4:18:38 PM",WARNING,Traceback (most recent call last): "Apr 16, 2022, 4:18:38 PM",WARNING,"During handling of the above exception, another exception occurred:" "Apr 16, 2022, 4:18:38 PM",WARNING,tornado.iostream.StreamClosedError: Stream is closed "Apr 16, 2022, 4:18:38 PM",WARNING, value = future.result() "Apr 16, 2022, 4:18:38 PM",WARNING," File ""/usr/local/lib/python3.7/dist-packages/tornado/gen.py"", line 1133, in run" "Apr 16, 2022, 4:18:38 PM",WARNING, yield fut "Apr 16, 2022, 4:18:38 PM",WARNING," File ""/usr/local/lib/python3.7/dist-packages/tornado/websocket.py"", line 874, in wrapper" "Apr 16, 2022, 4:18:38 PM",WARNING,Traceback (most recent call last): "Apr 16, 2022, 4:18:38 PM",WARNING,future: "Apr 16, 2022, 4:18:38 PM",WARNING,ERROR:asyncio:Future exception was never retrieved "Apr 16, 2022, 4:18:38 PM",INFO,Starting buffering for d5ff7869-edb3-4e31-a38e-20e2c655f7d2:c7df80dc0b1b4ae7959d1ea88b633edb "Apr 16, 2022, 4:16:35 PM",INFO,Adapting to protocol v5.1 for kernel d5ff7869-edb3-4e31-a38e-20e2c655f7d2 "Apr 16, 2022, 4:16:33 PM",INFO,Kernel started: d5ff7869-edb3-4e31-a38e-20e2c655f7d2 "Apr 16, 2022, 4:13:35 PM",INFO,Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). "Apr 16, 2022, 4:13:35 PM",INFO,http://172.28.0.12:9000/ "Apr 16, 2022, 4:13:35 PM",INFO,The Jupyter Notebook is running at: "Apr 16, 2022, 4:13:35 PM",INFO,0 active kernels "Apr 16, 2022, 4:13:35 PM",INFO,Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). "Apr 16, 2022, 4:13:35 PM",INFO,Serving notebooks from local directory: / "Apr 16, 2022, 4:13:35 PM",INFO,http://172.28.0.2:9000/ "Apr 16, 2022, 4:13:35 PM",INFO,The Jupyter Notebook is running at: "Apr 16, 2022, 4:13:35 PM",INFO,0 active kernels "Apr 16, 2022, 4:13:35 PM",INFO,google.colab serverextension initialized. "Apr 16, 2022, 4:13:35 PM",INFO,Serving notebooks from local directory: / "Apr 16, 2022, 4:13:35 PM",INFO,google.colab serverextension initialized. "Apr 16, 2022, 4:13:35 PM",WARNING, /root/.jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /root/.jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /root/.local/etc/jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /root/.local/etc/jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /usr/etc/jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /usr/etc/jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /usr/local/etc/jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /usr/local/etc/jupyter/jupyter_notebook_config.d/panel-client-jupyter.json "Apr 16, 2022, 4:13:35 PM",WARNING, /usr/local/etc/jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /usr/local/etc/jupyter/jupyter_notebook_config.d/panel-client-jupyter.json "Apr 16, 2022, 4:13:35 PM",WARNING, /etc/jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",WARNING, /etc/jupyter/jupyter_notebook_config.json "Apr 16, 2022, 4:13:35 PM",INFO,Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret "Apr 16, 2022, 4:13:35 PM",WARNING, FutureWarning) "Apr 16, 2022, 4:13:35 PM",WARNING,"/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py:2205: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use '/content' instead of '""/content""' if you require traitlets >=5." "Apr 16, 2022, 4:13:35 PM",WARNING, FutureWarning) "Apr 16, 2022, 4:13:35 PM",WARNING,"/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py:2205: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use '/' instead of '""/""' if you require traitlets >=5." "Apr 16, 2022, 4:13:35 PM",WARNING, FutureWarning) "Apr 16, 2022, 4:13:35 PM",WARNING,"/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py:2205: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use '172.28.0.12' instead of '""172.28.0.12""' if you require traitlets >=5." "Apr 16, 2022, 4:13:35 PM",INFO,Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret "Apr 16, 2022, 4:13:35 PM",WARNING, FutureWarning) "Apr 16, 2022, 4:13:35 PM",WARNING,"/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py:2205: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use '/content' instead of '""/content""' if you require traitlets >=5." "Apr 16, 2022, 4:13:35 PM",WARNING, FutureWarning) "Apr 16, 2022, 4:13:35 PM",WARNING,"/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py:2205: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use '/' instead of '""/""' if you require traitlets >=5." "Apr 16, 2022, 4:13:35 PM",WARNING, FutureWarning) "Apr 16, 2022, 4:13:35 PM",WARNING,"/usr/local/lib/python3.7/dist-packages/traitlets/traitlets.py:2205: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use '172.28.0.2' instead of '""172.28.0.2""' if you require traitlets >=5."
Any help would be greatly appreciated.
Solution 1:[1]
With the help of @r-beginners I was able to somewhat resolve this issue by reducing the image size (fig) down to about (8,8), which allowed me to render it entirely without errors.
Previously:
fig = plt.figure(figsize=(14,14))
After:
fig = plt.figure(figsize=(8,8))
Honestly, given how simple the graphic was, I didn't think the process would've hit a resource wall. However, there might be much more involved than I thought in the calculation and creation of the graphic, and just might be my naivety sustained.
Still, hope this helps someone else!
tl;dr - output file size too big, assume limit with Google Colab (free version), reduce output file size, success
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ilovegoodbread |
