Skip to content
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

write_image hangs #80

Closed
adammclaurin opened this issue Mar 10, 2021 · 12 comments
Closed

write_image hangs #80

adammclaurin opened this issue Mar 10, 2021 · 12 comments

Comments

@adammclaurin
Copy link

I'm using kaleido 0.2.1 with plotly 4.14.3 on Python 3.8.1 and RHEL Linux 7.9. I'm trying to run the below example notebook but the write_image() calls never return:
https://plotly.com/python/static-image-export/

I tried multiple image formats and nothing seems to work. Is this a known issue?

Thanks!

@jonmmease
Copy link
Collaborator

Hi @adammclaurin, Kaleido shold be compatible with that configuration. Does your system have SELinux running? If so, #37 might be helpful.

If not, try the instructions in #36 (comment) to see if we can get a little more logging info.

@adammclaurin
Copy link
Author

Thanks for the feedback @jonmmease . I confirmed that SELinux is not running.

Here's a screenshot of the backtrace that gets printed when I stop the Jupyter kernel while write_image() is hung:
kaleido backtrace

And here's a screenshot of the output of the debugging command you suggested:
kaleido stderror

Any suggestions?

@jonmmease
Copy link
Collaborator

Huh, that logging info is all normal.

Previously, some folks had an issue with Kaleido hanging while working behind a proxy that hung kaleido's attempt to pull MathJax from a CDN. So you can try two things from (#36 (comment))

  • Fully disconnect any internet connection and try the export
  • Try disabling mathjax support according to instructions in the linked issue.

Just FYI, kaleido 0.2.1 does bundle MathJax, but plotly.py still overrides the local MathJax path to point to the CDN location. In plotly.py 5, plotly.py will let kaleido use its local offline MathJax, so this won't be an issue any more.

@adammclaurin
Copy link
Author

Thanks @jonmmease, that was exactly the issue. I'm working in a private JupyterHub environment that doesn't have direct access to the internet. Disabling MathJax as you suggested fixed the issue.

Do you have an estimate of when plotly.py 5 will be generally available?

@nicolaskruchten
Copy link

Without committing strongly to any timeline, my hope is that plotly v5 will be available in late April/early May.

@chrispijo
Copy link

It seems that I ran into the same error, however, the proposed solution does not work. I tried the code snipped below and it remains hanging indefinitely. My setup is a Python 3.8.5 venv on Ubuntu (through WSL). Kaleido is version 0.2.1 and Plotly 4.14.3. Downgrading to kaleido 0.1.0 works.

import plotly.io as pio
pio.kaleido.scope.mathjax = None
import plotly.graph_objects as go
import json

# Figure
fig = go.Figure(
    data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])],
    layout=go.Layout(
        title=go.layout.Title(text="A Figure Specified By A Graph Object")
    )
)

# Display original figure
# fig.show()  # Works
fig.write_image("original_figure.png", format="png", engine="kaleido")  # Works

In Windows on Python 3.8 the code snippet does work. Also without setting mathjax to None.

@chrispijo
Copy link

chrispijo commented May 1, 2021

The temporary solution I posted above did not work on another setup. Now I am wondering if the problem is maybe not the same. On the bottom of this post the traceback after I run a KeyboardInterrupt (when it keeps hanging). It seems to be hanging in response = self._proc.stdout.readline(), does this mean that is the same issue?

Note: I installed plotly from jonmmease's branch 'kaleido_v5_updates'. Besides that, kaleido 0.2.1 is now installed. The reference to MathJax.js with this combo of plotly and kaleido is correct:

>>> import plotly.io as pio
>>> scope_pio = pio.kaleido.scope
>>> scope_pio.mathjax
'file:///ScratchProject/TestPlotlyUpdateInstallV1/uenv/lib/python3.8/site-packages/kaleido/executable/etc/mathjax/MathJax.js'
(uenv) chris@Notebook:/ScratchProject/TestPlotlyUpdateInstallV1$ python export_figure.py
^CTraceback (most recent call last):
  File "export_figure.py", line 18, in <module>
    fig.write_image(file=export_path, width=1280, height=720, scale=1.0, engine="kaleido", format="png")
  File "/ScratchProject/TestPlotlyUpdateInstallV1/uenv/lib/python3.8/site-packages/plotly/basedatatypes.py", line 3806, in write_image
    return pio.write_image(self, *args, **kwargs)
  File "/ScratchProject/TestPlotlyUpdateInstallV1/uenv/lib/python3.8/site-packages/plotly/io/_kaleido.py", line 258, in write_image
    img_data = to_image(
  File "/ScratchProject/TestPlotlyUpdateInstallV1/uenv/lib/python3.8/site-packages/plotly/io/_kaleido.py", line 144, in to_image
    img_bytes = scope.transform(
  File "/ScratchProject/TestPlotlyUpdateInstallV1/uenv/lib/python3.8/site-packages/kaleido/scopes/plotly.py", line 103, in transform
    response = self._perform_transform(
  File "/ScratchProject/TestPlotlyUpdateInstallV1/uenv/lib/python3.8/site-packages/kaleido/scopes/base.py", line 297, in _perform_transform
    response = self._proc.stdout.readline()
KeyboardInterrupt

@jonmmease
Copy link
Collaborator

Hi @chrispijo,

Would you mind opening a new issue and copying this info over there? My guess is that this is related to running on WSL, rather than the MathJax issue discussed in this thread.

In that new issue, could you please include the output of running the following command after using Ctrl+C to interrupt the write process:

import plotly.io as pio
scope = pio.kaleido.scope
print(scope._std_error.getvalue().decode())

Thanks!

@chrispijo
Copy link

Happy to do so.

@whaleprince
Copy link

It seems that I ran into the same error, however, the proposed solution does not work. I tried the code snipped below and it remains hanging indefinitely. My setup is a Python 3.8.5 venv on Ubuntu (through WSL). Kaleido is version 0.2.1 and Plotly 4.14.3. Downgrading to kaleido 0.1.0 works.

import plotly.io as pio
pio.kaleido.scope.mathjax = None
import plotly.graph_objects as go
import json

# Figure
fig = go.Figure(
    data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])],
    layout=go.Layout(
        title=go.layout.Title(text="A Figure Specified By A Graph Object")
    )
)

# Display original figure
# fig.show()  # Works
fig.write_image("original_figure.png", format="png", engine="kaleido")  # Works

In Windows on Python 3.8 the code snippet does work. Also without setting mathjax to None.

I have the same questions

@rhelmeczi
Copy link

Downgrading kaleido also worked for me, although 0.1.0 caused a different error, so I had to use 0.0.3

@gvwilson
Copy link
Collaborator

Thanks for your interest in Kaleido. We are currently working on an overhaul that might address your issue - we hope to have news in a few weeks and will post an update then. Thanks - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants