plotly / orca

Command line application for generating static images of interactive plotly charts
MIT License
294 stars 39 forks source link

write_image() fail with orca 1.2.1 #241

Open gree0299 opened 5 years ago

gree0299 commented 5 years ago

Hey all, having a lot of issues with Orca this past weekend trying to write_image() with a Scattermapbox. Was working flawlessly for a couple weeks and suddenly stopped working over this weekend. Lot of weird nuances with it so I will try and provide as much info as possible.

So a standard run of the program will just hang and produce:

Traceback (most recent call last): File "test.py", line 30, in fig.write_image("fig1.png") File "C:\Users\ _\Miniconda3\lib\site-packages\plotly\basedatatypes.py", line 2684, in write_image return pio.writeimage(self, *args, **kwargs) File "C:\Users\ \Miniconda3\lib\site-packages\plotly\io_orca.py", line 1704, in write_image fig, format=format, scale=scale, width=width, height=height, validate=validate File "C:\Users\ ___\Miniconda3\lib\site-packages\plotly\io_orca.py", line 1528, in to_image info=status_str ValueError: For some reason plotly.py was unable to communicate with the local orca server process, even though the server process seems to be running.

Please review the process and connection information below:

state: running
executable: C:\Users\_______\Miniconda3\orca.CMD
version: 1.2.1
port: 8123
pid: 6524
command: ['C:\\Users\\_______\\Miniconda3\\orca.CMD', 'serve', '-p', '8123', '--plotly', 'C:\\Users\\_______\\Miniconda3\\lib\\site-packages\\plotly\\package_data\\plotly.min.js', '--graph-only', '--mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js', '--mapbox-access-token', '_______']

Following that, I tried the run the server manually to watch the output which returns:

{"severity":"ERROR","textPayload":"gpu process crashed - false"} {"severity":"ERROR","textPayload":"renderer error - Uncaught TypeError: Failed to execute 'shaderSource' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLShader'."} {"severity":"ERROR","textPayload":"renderer error - Uncaught TypeError: Failed to execute 'shaderSource' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLShader'."} {"severity":"ERROR","textPayload":"renderer error - Uncaught TypeError: Failed to execute 'shaderSource' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLShader'."} {"severity":"ERROR","textPayload":"525 - plotly.js error","labels":{"fid":null}}

Interestingly, if I run the server with "--debug", and then try write_image(), the operation succeeds. On top of that, it is able to write_image() with every other type of graph I use which further adds to my confusion.


Versions:

plotly 4.0.0 plotly-orca 1.2.1 psutil 5.6.3 Windows 10 (latest version) GPU is updated to latest version

I have also tested the code on a work laptop which is also running Windows 10 and it has the same issues. For simplicity, I have been testing with https://plot.ly/python/scattermapbox/#basic-example

Any help is appreciated

gree0299 commented 5 years ago

Update for anyone else that encounters this issue, I figured out a hacky workaround to get the process working again.

Before you attempt to write_image() with a Scattermapbox, create a subprocess to manually launch the Plotly-orca server with the --keepalive option. For example,

subprocess.Popen([“orca”, “serve”, “-p”, “8123”, “–plotly plotly.min.js”, “–graph-only”, “–mathjax”, “https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js”, “–mapbox-access-token”, “tokentokentokentokentoken”, “–keep-alive”], stdout=subprocess.PIPE, shell=True)

It would be awesome to have this as a plotly.io.orca.config option.

ociule commented 4 years ago

I'm also seeing this fail with orca 1.2.1 (and also 1.1.1), on Windows Server 2008, with a non-admin account, with any plot type, not just Scattermapbox. With an admin account, it works fine.

Doing the test gree0299 recommends works fine: even with a non-admin account, plotly can communicate with the orca launched manually, from a non-admin account. I'm not very familiar with Windows security so I'm stumped. There is no windows firewall.

To bypass the issue, I'm planning to use an external orca, like this: https://community.plot.ly/t/plotly-io-with-external-orca/25600

I also :+1: the idea of being able to just configure pio.orca.config to use an external orca, without the hack described in the link above. It would still involve some work to start orca as a service and reliably relaunch it if it fails. Maybe keep a pool of orca processes behind a load balancer.

Edit: managed to track down my issue by running orca directly from the notebook, got the following error:

{"severity":"ERROR","textPayload":"Error: EPERM: operation not permitted, open 'C:\\Users\\ADMIN_USER\\AppData\\Local\\Temp\\orca-build\\index-aff66e2f-d366-4e8b-83d5-3b259ef8d9a0.html'"}

That ADMIN_USER is not the user running the notebook, the non-admin user running the notebook cannot access that folder, the %TEMP% variable value is wrong for some reason in my notebook. Orca just tries to use that %TEMP% value and of course it's not working.

Edit: traced that wrong TEMP env var value to my specific notebook setup: using jupyterhub on Windows with winlocalprocessspawner. It's a bug in winlocalprocessspawner.

STB0001 commented 4 years ago

I encountered this issue when generating a series of eight scatter plots. The first scatterplot had 200,000 data points in it. The second one had the original data points, but then added another 200,000 color coded for another parameter. The error message was:

Traceback (most recent call last):

File "C:\Users_\Documents_ \Work\Programming\Python Scripts\Crossplots.py", line 1159, in ExtractAndPlot_ScatterPlots (FileParameters, PlotParameters)

File "C:\Users_\Documents_ \Work\Programming\Python Scripts\Crossplots.py", line 908, in ExtractAndPlot_ScatterPlots fig.write_image(PlotParameters.ScatterPlotFileName)

File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\basedatatypes.py", line 2813, in write_image return pio.write_image(self, *args, **kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\io_orca.py", line 1768, in write_image fig, format=format, scale=scale, width=width, height=height, validate=validate

File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\io_orca.py", line 1592, in to_image info=status_str

ValueError: For some reason plotly.py was unable to communicate with the local orca server process, even though the server process seems to be running.

Please review the process and connection information below:

orca status ____- state: running executable: C:\ProgramData\Anaconda3\orca.CMD version: 1.2.1 port: 55461 pid: 154272 command: ['C:\ProgramData\Anaconda3\orca.CMD', 'serve', '-p', '55461', 'plotly', 'C:\ProgramData\Anaconda3\lib\site-packages\plotly\package_data\plotly.min.js', 'graph-only', 'mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js']

Given that the code to generate the eight plots were in a single function, I simply made a separate function for the plot that caused the problem, put the code into it, and called it from the original function. That worked. All eight plots were generated.