plotly / Kaleido

Fast static image export for web-based visualization libraries with zero dependencies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kaleido write_image is crashing in docker container on windows 10

Slayvin opened this issue · comments

Hello,

I'm writing a python script to render a plotly graph to an image with kaleido.
unfortunately, it keeps crashing on the first call. I've seen many users with the same issue, but none of the solutions work so far...

My environment:
Windows 10 wsl2 with a Debian container
python 3.9
plotly 5.12.0
kaleido 0.2.1

Here is the python code snippet I'm using:

import plotly.graph_objects as go
import plotly.io as pio
pio.kaleido.scope.chromium_args += ("--single-process", "--disable-gpu", "--headless", "--no-sandbox",)
pio.kaleido.scope.mathjax = None

print("Generating graph..")
fig = go.Figure(data=[go.Bar(x=x, y=y, marker_color='#6AB5FD')])
#...

try:
      fig.write_image(pictureFilename, width=500, height=500, scale=4)
      print("--> graph image saved")
except:
      print(pio.kaleido.scope._std_error.getvalue().decode("utf8"))
      print("--> graph image error")

Here is the docker container log output:

#FailureMessage Object: 0x7fa44f6e99f0#0 0x55720e553d79 base::debug::CollectStackTrace()
2023-02-03 11:56:58 #1 0x55720e4d1633 base::debug::StackTrace::StackTrace()
2023-02-03 11:56:58 #2 0x55721070c33d gin::(anonymous namespace)::PrintStackTrace()
2023-02-03 11:56:58 #3 0x55720f9c6995 V8_Fatal()
2023-02-03 11:56:58 #4 0x55720d5a84d8 v8::internal::V8::FatalProcessOutOfMemory()
2023-02-03 11:56:58 #5 0x55720d7e9e62 v8::internal::IsolateAllocator::InitReservation()
2023-02-03 11:56:58 #6 0x55720d7e9a18 v8::internal::IsolateAllocator::IsolateAllocator()
2023-02-03 11:56:58 #7 0x55720d6c9920 v8::internal::Isolate::New()
2023-02-03 11:56:58 #8 0x5572107085f1 gin::IsolateHolder::IsolateHolder()
2023-02-03 11:56:58 #9 0x55721058c43e blink::V8PerIsolateData::V8PerIsolateData()
2023-02-03 11:56:58 #10 0x55721058cc09 blink::V8PerIsolateData::Initialize()
2023-02-03 11:56:58 #11 0x5572104a96d4 blink::V8Initializer::InitializeMainThread()
2023-02-03 11:56:58 #12 0x5572110b5244 blink::(anonymous namespace)::InitializeCommon()
2023-02-03 11:56:58 #13 0x557211763ef7 content::RenderThreadImpl::InitializeWebKit()
2023-02-03 11:56:58 #14 0x557211762bef content::RenderThreadImpl::Init()
2023-02-03 11:56:58 #15 0x55721176387b content::RenderThreadImpl::RenderThreadImpl()
2023-02-03 11:56:58 #16 0x557210ab9918 content::InProcessRendererThread::Init()
2023-02-03 11:56:58 #17 0x55720e54180c base::Thread::ThreadMain()
2023-02-03 11:56:58 #18 0x55720e563caa base::(anonymous namespace)::ThreadFunc()
2023-02-03 11:56:58 #19 0x7fa4585a1ea7 start_thread
2023-02-03 11:56:58 #20 0x7fa45797baef clone
2023-02-03 11:56:58 Received signal 4 ILL_ILLOPN 55720f9c9932
2023-02-03 11:56:58 #0 0x55720e553d79 base::debug::CollectStackTrace()
2023-02-03 11:56:58 #1 0x55720e4d1633 base::debug::StackTrace::StackTrace()
2023-02-03 11:56:58 #2 0x55720e55395b base::debug::(anonymous namespace)::StackDumpSignalHandler()
2023-02-03 11:56:58 #3 0x7fa4585ad140 (/lib/x86_64-linux-gnu/libpthread-2.31.so+0x1313f)
2023-02-03 11:56:58 #4 0x55720f9c9932 v8::base::OS::Abort()
2023-02-03 11:56:58 #5 0x55720f9c69a2 V8_Fatal()
2023-02-03 11:56:58 #6 0x55720d5a84d8 v8::internal::V8::FatalProcessOutOfMemory()
2023-02-03 11:56:58 #7 0x55720d7e9e62 v8::internal::IsolateAllocator::InitReservation()
2023-02-03 11:56:58 #8 0x55720d7e9a18 v8::internal::IsolateAllocator::IsolateAllocator()
2023-02-03 11:56:58 #9 0x55720d6c9920 v8::internal::Isolate::New()
2023-02-03 11:56:58 #10 0x5572107085f1 gin::IsolateHolder::IsolateHolder()
2023-02-03 11:56:58 #11 0x55721058c43e blink::V8PerIsolateData::V8PerIsolateData()
2023-02-03 11:56:58 #12 0x55721058cc09 blink::V8PerIsolateData::Initialize()
2023-02-03 11:56:58 #13 0x5572104a96d4 blink::V8Initializer::InitializeMainThread()
2023-02-03 11:56:58 #14 0x5572110b5244 blink::(anonymous namespace)::InitializeCommon()
2023-02-03 11:56:58 #15 0x557211763ef7 content::RenderThreadImpl::InitializeWebKit()
2023-02-03 11:56:58 #16 0x557211762bef content::RenderThreadImpl::Init()
2023-02-03 11:56:58 #17 0x55721176387b content::RenderThreadImpl::RenderThreadImpl()
2023-02-03 11:56:58 #18 0x557210ab9918 content::InProcessRendererThread::Init()
2023-02-03 11:56:58 #19 0x55720e54180c base::Thread::ThreadMain()
2023-02-03 11:56:58 #20 0x55720e563caa base::(anonymous namespace)::ThreadFunc()
2023-02-03 11:56:58 #21 0x7fa4585a1ea7 start_thread
2023-02-03 11:56:58 #22 0x7fa45797baef clone
2023-02-03 11:56:58   r8: 0000000000000000  r9: 0000000000000000 r10: 000000000001369a r11: 0000000000000000
2023-02-03 11:56:58  r12: 0000003000000008 r13: 00007fa44f6e9d00 r14: 000055720a07b8a6 r15: 00007fa44f6e9cb0
2023-02-03 11:56:58   di: 00007fa457a50980  si: 0000000000000000  bp: 00007fa44f6e99e0  bx: 00007fa457a4f780
2023-02-03 11:56:58   dx: 0000000000000001  ax: 0000000000000000  cx: 0000000000000c00  sp: 00007fa44f6e99e0
2023-02-03 11:56:58   ip: 000055720f9c9932 efl: 0000000000010202 cgf: 002b000000000033 erf: 0000000000000000
2023-02-03 11:56:58  trp: 0000000000000006 msk: 0000000000000000 cr2: 0000000000000000
2023-02-03 11:56:58 [end of stack trace]
2023-02-03 11:56:58 Calling _exit(1). Core file will not be generated.

It looks like it's a memory issue with the internal javascript engine of chromium (V8)

Note that Kaleido will start when executed in a docker terminal, and will generate an output.
It is crashing when executed from the python script above.

Here is the output when launched in terminal:

[0203/113742.397060:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
{"code": 0, "message": "Success", "result": null, "version": "0.2.1"}
[0203/113742.651941:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale

If I copy-paste this afterwards, it will output some result

{"data":{"layout": {}}, "format":"png"}

Hi, this is affecting us as well.
Current workaround is downgrade to 0.1.0

I get the similar error where it crashes under ubuntu 20.0. It works for a while and then hangs all of a sudden.

[0404/171525.764737:ERROR:zygote_host_impl_linux.cc(263)] Failed to adjust OOM score of renderer with pid 224: Permission denied (13)
[0404/171525.767326:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/grpc/_server.py", line 494, in _call_behavior
    response_or_iterator = behavior(argument, context)  
  File "/usr/local/lib/python3.8/dist-packages/plotly/basedatatypes.py", line 3758, in to_image
    return pio.to_image(self, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/plotly/io/_kaleido.py", line 144, in to_image
    img_bytes = scope.transform(
  File "/usr/local/lib/python3.8/dist-packages/kaleido/scopes/plotly.py", line 153, in transform
    response = self._perform_transform(
  File "/usr/local/lib/python3.8/dist-packages/kaleido/scopes/base.py", line 293, in _perform_transform
    self._ensure_kaleido()
  File "/usr/local/lib/python3.8/dist-packages/kaleido/scopes/base.py", line 198, in _ensure_kaleido
    raise ValueError(message)
ValueError: Failed to start Kaleido subprocess. Error stream:

[0404/171525.735950:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
[0404/171525.746247:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
[0404/171525.746267:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
[0404/171525.754043:ERROR:zygote_host_impl_linux.cc(263)] Failed to adjust OOM score of renderer with pid 222: Permission denied (13)
[0404/171525.764737:ERROR:zygote_host_impl_linux.cc(263)] Failed to adjust OOM score of renderer with pid 224: Permission denied (13)
[0404/171525.767326:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale