orca icon indicating copy to clipboard operation
orca copied to clipboard

Error with exporting large data image

Open rrazaghi opened this issue 5 years ago • 5 comments

So fig.write_image works just fine on doing distplot on a dataframe of a few 100k rows. However, when I pass the 1 million rows threshold it outputs the "plotly cannot communicate with orca sometimes" error. Is there any workaround for this?

Thanks in advance!

-Roham

rrazaghi avatar Jul 30 '19 05:07 rrazaghi

have u encountered this error?

"Error: The orca command-line utility is required for this functionality." I dont know what else I can do ! thanks

dplazas avatar Apr 02 '20 18:04 dplazas

Hi, I have the same issue. Here is the error message when I try to export a large plot:

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: /Users/guillaumerozier/opt/anaconda3/bin/orca
    version: 1.3.0
    port: 50438
    pid: 90835
    command: ['/Users/guillaumerozier/opt/anaconda3/bin/orca', 'serve', '-p', '50438', '--plotly', '/Users/guillaumerozier/opt/anaconda3/lib/python3.7/site-packages/plotly/package_data/plotly.min.js', '--graph-only', '--mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js']

rozierguillaume avatar Apr 14 '20 10:04 rozierguillaume

Any updates? I have the same issue. Doing choropleth maps with pff.create_choropleth(), scope is USA counties, I make a map each day for about 110 days. A large list of binning_endpoints seems to trigger the crash, but it depends on the data - in some cases it's fine with thousands of endpoints, in other cases 200 crash it.

Dataframe has one column for each county, one row for each day.

import plotly.figure_factory as pff
import os

def make_images(arglist):
    df, endpts, map, type, scale = arglist
    datelist = df.index.tolist()
    for ddate in datelist:
        dlist = ddate.split('/')
        datenow = '20' + dlist[2] + dlist[0].rjust(2, '0') + dlist[1].rjust(2, '0')
        datenowslash = '20' + dlist[2] + '/' + dlist[0].rjust(2, '0') + '/' + dlist[1].rjust(2, '0')

        fig = pff.create_choropleth(
            fips=df.columns.tolist(),
            values=df.loc[ddate],
            scope=[map],
            county_outline={'color': 'rgb(0,0,0)', 'width': 0.5},
            binning_endpoints=endpts,
        )

        fig.update_layout(
            autosize=False,
            width=2000,
            height=1066,
            showlegend=False,
            title={
              'text': '<b>' + map.upper() + ' BIG MAP<br>' + type + '<br>' + scale + '<br>' + datenowslash + '</b>',
              'y': 0.2,
              'x': 0.1,
              'xanchor': 'left',
              'yanchor': 'middle'},
        )

        imgpath = os.path.join(type.replace(' ', '_'), 'frame-' + datenow + '.png')

        fig.write_image(imgpath, scale=1.0)

I have several workers with that function, one for each CPU. After dozens of images, they start to crash.

---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/plotly/io/_orca.py", line 1562, in to_image
    figure=fig_dict, format=format, scale=scale, width=width, height=height
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/retrying.py", line 212, in call
    raise attempt.get()
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/six.py", line 703, in reraise
    raise value
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/plotly/io/_orca.py", line 1477, in request_image_with_retrying
    raise OSError("522: client socket timeout")
OSError: 522: client socket timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/florin/opt/anaconda3/lib/python3.7/multiprocessing/pool.py", line 121, in worker
    result = (True, func(*args, **kwds))
  File "/Users/florin/opt/anaconda3/lib/python3.7/multiprocessing/pool.py", line 44, in mapstar
    return list(map(*args))
  File "/Users/florin/notebook/covid19us/workers.py", line 35, in make_images
    fig.write_image(imgpath, scale=1.0)
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/plotly/basedatatypes.py", line 2824, in write_image
    return pio.write_image(self, *args, **kwargs)
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/plotly/io/_orca.py", line 1770, in write_image
    fig, format=format, scale=scale, width=width, height=height, validate=validate
  File "/Users/florin/opt/anaconda3/lib/python3.7/site-packages/plotly/io/_orca.py", line 1594, 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: /Users/florin/opt/anaconda3/bin/orca
    version: 1.3.1
    port: 50094
    pid: 1574
    command: ['/Users/florin/opt/anaconda3/bin/orca', 'serve', '-p', '50094', '--plotly', '/Users/florin/opt/anaconda3/lib/python3.7/site-packages/plotly/package_data/plotly.min.js', '--graph-only', '--mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js']



"""

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-12-475aa2260917> in <module>
     15     # call workers
     16     work_out = p.map(make_images, usabsarglist)
---> 17     work_out = p.map(make_images, usrelarglist)
     18     p.close()

~/opt/anaconda3/lib/python3.7/multiprocessing/pool.py in map(self, func, iterable, chunksize)
    266         in a list that is returned.
    267         '''
--> 268         return self._map_async(func, iterable, mapstar, chunksize).get()
    269 
    270     def starmap(self, func, iterable, chunksize=None):

~/opt/anaconda3/lib/python3.7/multiprocessing/pool.py in get(self, timeout)
    655             return self._value
    656         else:
--> 657             raise self._value
    658 
    659     def _set(self, i, obj):

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: /Users/florin/opt/anaconda3/bin/orca
    version: 1.3.1
    port: 50094
    pid: 1574
    command: ['/Users/florin/opt/anaconda3/bin/orca', 'serve', '-p', '50094', '--plotly', '/Users/florin/opt/anaconda3/lib/python3.7/site-packages/plotly/package_data/plotly.min.js', '--graph-only', '--mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js']

FlorinAndrei avatar May 14 '20 19:05 FlorinAndrei

It's failing because of a timeout stop_max_delay=60000. Not sure why that's there.

In case it's helpful, this workaround does the trick for me.

# Disable the orca response timeout.
import plotly.io._orca
import retrying
unwrapped = plotly.io._orca.request_image_with_retrying.__wrapped__
wrapped = retrying.retry(wait_random_min=1000)(unwrapped)
plotly.io._orca.request_image_with_retrying = wrapped

energizah avatar May 17 '20 23:05 energizah

I had the same issue on MacOS and it was caused because the electron app (that launches on executing fig.write_image) was interrupted. Restarting my IDE and rerunning the script solved the issue.

rjcnrd avatar Feb 15 '21 16:02 rjcnrd