-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kaleido hangs on repeated write_image calls. #42
Comments
Thanks for the report and example @36000, I was able to reproduce the issue. Here is my output (after stopping the kernel after hanging for a minute or two):
There was also some internally buffered error log import plotly.io as pio
scope = pio.kaleido.scope
print(scope._std_error.getvalue().decode())
|
So it looks like we have a object/memory leak in the JavaScript portion of kaleido that shows up here due to the large figure size. This will probably take some time to track down, so here's a workaround you can use in the meantime import pickle
import tempfile
from time import time
import numpy as np
import os
import plotly.io as pio
scope = pio.kaleido.scope
with open('example_fig.obj', 'rb') as ff:
figure = pickle.load(ff)
# tdir = tempfile.gettempdir()
tdir = './out4'
os.makedirs(tdir)
n_frames=60
zoom=2.5
z_offset=0.5
for i in range(n_frames):
start = time()
theta = (i * 6.28) / n_frames
camera = dict(
eye=dict(x=np.cos(theta) * zoom,
y=np.sin(theta) * zoom, z=z_offset)
)
figure.update_layout(scene_camera=camera)
figure.write_image(tdir + f"/tgif{i}.png")
# Shutdown kaleido subprocess to free memory, it will
# be started again on next image export request
scope._shutdown_kaleido()
print(time()-start) The Hope this holds you over until we can track this down and get a fix out. Thanks again for the report. |
Do you have any tips / tricks on how to speed up this gif creation process? I don't know the details, but it seems like each time I call write_image, under the hood, I am opening up the same figure using chromium. Is there an easy way to open the figure once, then rotate and take screenshots within the browser? |
I don't know of anything different to do right now. It would take some benchmarking to hone in on what would actually is taking so long right now. I expect that a lot of the time is being taken up with JSON serialization (Python to C++, then C++ to JavaScript) given the size of the figures. Do these figures use large numpy arrays? We've talked about optimizing this serialization path in the past, but haven't gotten it off the ground yet. All that said, I could see a place for adding support to kaleido for batching image export requests. One option would be to support inputting figures that define |
My inputs to the scatter3d traces are long numpy arrays, I think those are what make the figures so big. I like that last idea of adding support for inputting figures that define frames. |
In hope that it stops kaleido's memory leak problem as discussed in: plotly/Kaleido#49 plotly/Kaleido#42
I am trying to use kaleido to make a gif, by writing out a series of png's then concatenating them together. The first few calls to write_image succeed, but at some point it just hangs. I have pickled my plotly figure and attach it to this post, as well as code to reproduce the phenomenon. I am using
kaleido==0.0.3.post1
but I have tried it on many other pip install-able versions (0.0.1, 0.0.2, 0.0.3) to get the same effect. BTW, I really like this software! It makes it so much easier to write out plotly figures.example_fig.zip
This is the output before it stalls:
The text was updated successfully, but these errors were encountered: