plotly / Kaleido

Fast static image export for web-based visualization libraries with zero dependencies
Other
349 stars 33 forks source link

Error using Kaleido with Jupyter Docker Stacks #88

Closed polakowo closed 3 years ago

polakowo commented 3 years ago

How to reproduce:

Dockerfile:

FROM jupyter/base-notebook
RUN pip install plotly kaleido

Build and run:

docker build -t test . 
docker run -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes -it test

In Jupyter Lab:

import plotly.io as pio
print(pio.to_image({}, engine="kaleido", format="svg"))

Raises error:

ValueError                                Traceback (most recent call last)
<ipython-input-1-9938f40675d3> in <module>
      1 import plotly.io as pio
----> 2 print(pio.to_image({}, engine="kaleido", format="svg"))

/opt/conda/lib/python3.8/site-packages/plotly/io/_kaleido.py in to_image(fig, format, width, height, scale, validate, engine)
    129     # ---------------
    130     fig_dict = validate_coerce_fig_to_dict(fig, validate)
--> 131     img_bytes = scope.transform(
    132         fig_dict, format=format, width=width, height=height, scale=scale
    133     )

/opt/conda/lib/python3.8/site-packages/kaleido/scopes/plotly.py in transform(self, figure, format, width, height, scale)
    151         # Transform in using _perform_transform rather than superclass so we can access the full
    152         # response dict, including error codes.
--> 153         response = self._perform_transform(
    154             figure, format=format, width=width, height=height, scale=scale
    155         )

/opt/conda/lib/python3.8/site-packages/kaleido/scopes/base.py in _perform_transform(self, data, **kwargs)
    291         """
    292         # Ensure that kaleido subprocess is running
--> 293         self._ensure_kaleido()
    294 
    295         # Perform export

/opt/conda/lib/python3.8/site-packages/kaleido/scopes/base.py in _ensure_kaleido(self)
    196                             self._get_decoded_std_error()
    197                         )
--> 198                         raise ValueError(message)
    199                     else:
    200                         startup_response = json.loads(startup_response_string)

ValueError: Failed to start Kaleido subprocess. Error stream:

[0503/212439.811966:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
[0503/212439.945587:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
[0503/212439.946848:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
[0503/212439.950566:FATAL:zygote_main_linux.cc(161)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded(). 
#0 0x004004e28d79 base::debug::CollectStackTrace()
#1 0x004004da6633 base::debug::StackTrace::StackTrace()
#2 0x004004db615f logging::LogMessage::~LogMessage()
#3 0x004004db6cde logging::LogMessage::~LogMessage()
#4 0x004004b21345 content::ZygoteMain()
#5 0x004004b0e8ea content::RunZygote()
#6 0x004004b0fb64 content::ContentMainRunnerImpl::Run()
#7 0x004004b0d374 content::RunContentProcess()
#8 0x004004b0dcfc content::ContentMain()
#9 0x004004b5f182 headless::(anonymous namespace)::RunContentMain()
#10 0x004004b5efbb headless::RunChildProcessIfNeeded()
#11 0x004002b7df09 main
#12 0x00400aa900b3 __libc_start_main
#13 0x004002b773ea _start

Received signal 6
#0 0x004004e28d79 base::debug::CollectStackTrace()
#1 0x004004da6633 base::debug::StackTrace::StackTrace()
#2 0x004004e2895b [0503/212439.949721:FATAL:zygote_main_linux.cc(161)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded(). 
#0 0x004004e28d79 base::debug::CollectStackTrace()
#1 0x004004da6633 base::debug::StackTrace::StackTrace()
#2 0x004004db615f logging::LogMessage::~LogMessage()
#3 0x004004db6cde logging::LogMessage::~LogMessage()
#4 0x004004b21345 content::ZygoteMain()
#5 0x004004b0e8ea content::RunZygote()
#6 0x004004b0fb64 content::ContentMainRunnerImpl::Run()
#7 0x004004b0d374 content::RunContentProcess()
#8 0x004004b0dcfc content::ContentMain()
#9 0x004004b5f182 headless::(anonymous namespace)::RunContentMain()
#10 0x004004b5efbb headless::RunChildProcessIfNeeded()
#11 0x004002b7df09 main
#12 0x00400aa900b3 __libc_start_main
#13 0x004002b773ea _start

Received signal 6
#0 base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x004009f083c0 0x004004e28d79 (/usr/lib/x86_64-linux-gnu/libpthread-2.31.so+0x153bf)
#4 0x00400aaaf18b gsignal
#5 0x00400aa8e859 abort
#6 0x004004e278f5 base::debug::CollectStackTrace()
#1 0x004004da6633 base::debug::BreakDebugger()
#7 0x004004db65b2 base::debug::StackTrace::StackTrace()
#2 0x004004e2895b logging::LogMessage::~LogMessage()
#8 0x004004db6cde base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x004009f083c0 (/usr/lib/x86_64-linux-gnu/libpthread-2.31.so+0x153bf)
#4 0x00400aaaf18b gsignal
#5 0x00400aa8e859 abort
#6 0x004004e278f5 logging::LogMessage::~LogMessage()
#9 0x004004b21345 base::debug::BreakDebugger()
#7 0x004004db65b2 content::ZygoteMain()
#10 0x004004b0e8ea logging::LogMessage::~LogMessage()
#8 0x004004db6cde content::RunZygote()
#11 0x004004b0fb64 content::ContentMainRunnerImpl::Run()
logging::LogMessage::~LogMessage()
#9 0x004004b21345 #12 0x004004b0d374 content::ZygoteMain()
#10 0x004004b0e8ea content::RunContentProcess()
#13 0x004004b0dcfc content::RunZygote()
#11 0x004004b0fb64 content::ContentMain()
#14 0x004004b5f182 content::ContentMainRunnerImpl::Run()
#12 0x004004b0d374 headless::(anonymous namespace)::RunContentMain()
#15 0x004004b5efbb content::RunContentProcess()
#13 0x004004b0dcfc headless::RunChildProcessIfNeeded()
#16 0x004002b7df09 main
#17 0x00400aa900b3 __libc_start_main
#18 0x004002b773ea content::ContentMain()
#14 0x004004b5f182 headless::(anonymous namespace)::RunContentMain()
#15 0x004004b5efbb headless::RunChildProcessIfNeeded()
#16 0x004002b7df09 main
#17 0x00400aa900b3 __libc_start_main
#18 0x004002b773ea _start
  r8: 0000000000000000  r9: 0000004009eb4770 r10: 0000000000000008 r11: 000000400ac29780
 r12: 0000004009eb5210 r13: 00003e96ebc12dc0 r14: 00003e96ebc12dd0 r15: 00003e96ebc12dd8
  di: 0000000000000002  si: 0000004009eb4770  bp: 0000004009eb49c0  bx: 000000400b066500
  dx: 0000000000000000  ax: 0000000000000000  cx: 0000000000000027  sp: 0000004009eb4770
  ip: 000000400aaaf18b efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
 trp: ffffffffffffffff msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.
_start
  r8: 0000000000000000  r9: 0000004009eb4760 r10: 0000000000000008 r11: 000000400ac29780
 r12: 0000004009eb5200 r13: 00001f37a30a4dc0 r14: 00001f37a30a4dd0 r15: 00001f37a30a4dd8
  di: 0000000000000002  si: 0000004009eb4760  bp: 0000004009eb49b0  bx: 000000400b066500
  dx: 0000000000000000  ax: 0000000000000000  cx: 0000000000000027  sp: 0000004009eb4760
  ip: 000000400aaaf18b efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
 trp: ffffffffffffffff msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.
[0503/212440.297931:ERROR:file_path_watcher_linux.cc(315)] inotify_init() failed: Function not implemented (38)
[0503/212440.383015:WARNING:gpu_process_host.cc(1274)] The GPU process has crashed 1 time(s)
qemu: unknown option 'type=utility'
[0503/212440.496789:WARNING:gpu_process_host.cc(1274)] The GPU process has crashed 2 time(s)
[0503/212440.500567:WARNING:gpu_process_host.cc(1274)] The GPU process has crashed 3 time(s)
[0503/212440.506316:WARNING:gpu_process_host.cc(1274)] The GPU process has crashed 4 time(s)
[0503/212440.561000:ERROR:network_service_instance_impl.cc(286)] Network service crashed, restarting service.
[0503/212440.561875:WARNING:gpu_process_host.cc(1274)] The GPU process has crashed 5 time(s)
qemu: unknown option 'type=utility'
[0503/212440.609429:WARNING:gpu_process_host.cc(1274)] The GPU process has crashed 6 time(s)
[0503/212440.609590:ERROR:network_service_instance_impl.cc(286)] Network service crashed, restarting service.
[0503/212440.609732:FATAL:gpu_data_manager_impl_private.cc(407)] GPU process isn't usable. Goodbye.
#0 0x004004e28d79 base::debug::CollectStackTrace()
#1 0x004004da6633 base::debug::StackTrace::StackTrace()
#2 0x004004db615f logging::LogMessage::~LogMessage()
#3 0x004003912907 content::(anonymous namespace)::IntentionallyCrashBrowserForUnusableGpuProcess()
#4 0x0040039106be content::GpuDataManagerImplPrivate::FallBackToNextGpuMode()
#5 0x00400390ec53 content::GpuDataManagerImpl::FallBackToNextGpuMode()
#6 0x004003918f5f content::GpuProcessHost::RecordProcessCrash()
#7 0x0040037a36d3 content::BrowserChildProcessHostImpl::OnProcessLaunchFailed()
#8 0x0040038031f0 content::internal::ChildProcessLauncherHelper::PostLaunchOnClientThread()
#9 0x004003803435 base::internal::Invoker<>::RunOnce()
#10 0x004004dec306 base::TaskAnnotator::RunTask()
#11 0x004004dfdcf6 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl()
#12 0x004004dfd9ea base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()
#13 0x004004e4a899 base::MessagePumpLibevent::Run()
#14 0x004004dfe59b base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run()
#15 0x004004dd79bd base::RunLoop::Run()
#16 0x0040037bff18 content::BrowserProcessSubThread::IOThreadRun()
#17 0x004004e16874 base::Thread::ThreadMain()
#18 0x004004e38caa base::(anonymous namespace)::ThreadFunc()
#19 0x004009efc609 start_thread
#20 0x00400ab8b293 clone
Task trace:
#0 0x00400380305e content::internal::ChildProcessLauncherHelper::PostLaunchOnLauncherThread()
#1 0x004003802afc content::internal::ChildProcessLauncherHelper::StartLaunchOnClientThread()
#2 0x004003d347c2 content::VizProcessTransportFactory::ConnectHostFrameSinkManager()
#3 0x00400545826f mojo::SimpleWatcher::Context::Notify()
#4 0x004003d347c2 content::VizProcessTransportFactory::ConnectHostFrameSinkManager()
Task trace buffer limit hit, update PendingTask::kTaskBacktraceLength to increase.

Received signal 6
#0 0x004004e28d79 base::debug::CollectStackTrace()
#1 0x004004da6633 base::debug::StackTrace::StackTrace()
#2 0x004004e2895b base::debug::(anonymous namespace)::StackDumpSignalHandler()
#3 0x004009f083c0 (/usr/lib/x86_64-linux-gnu/libpthread-2.31.so+0x153bf)
#4 0x00400aaaf18b gsignal
#5 0x00400aa8e859 abort
#6 0x004004e278f5 base::debug::BreakDebugger()
#7 0x004004db65b2 logging::LogMessage::~LogMessage()
#8 0x004003912907 content::(anonymous namespace)::IntentionallyCrashBrowserForUnusableGpuProcess()
#9 0x0040039106be content::GpuDataManagerImplPrivate::FallBackToNextGpuMode()
#10 0x00400390ec53 content::GpuDataManagerImpl::FallBackToNextGpuMode()
#11 0x004003918f5f content::GpuProcessHost::RecordProcessCrash()
#12 0x0040037a36d3 content::BrowserChildProcessHostImpl::OnProcessLaunchFailed()
#13 0x0040038031f0 content::internal::ChildProcessLauncherHelper::PostLaunchOnClientThread()
#14 0x004003803435 base::internal::Invoker<>::RunOnce()
#15 0x004004dec306 base::TaskAnnotator::RunTask()
#16 0x004004dfdcf6 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl()
#17 0x004004dfd9ea base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()
#18 0x004004e4a899 base::MessagePumpLibevent::Run()
#19 0x004004dfe59b base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run()
#20 0x004004dd79bd base::RunLoop::Run()
#21 0x0040037bff18 content::BrowserProcessSubThread::IOThreadRun()
#22 0x004004e16874 base::Thread::ThreadMain()
#23 0x004004e38caa base::(anonymous namespace)::ThreadFunc()
#24 0x004009efc609 start_thread
#25 0x00400ab8b293 clone
  r8: 0000000000000000  r9: 000000400d3502a0 r10: 0000000000000008 r11: 0000000000000000
 r12: 000000400d350d40 r13: 000000400d3515a0 r14: 000000400d3515b0 r15: 000000400d3515b8
  di: 0000000000000002  si: 000000400d3502a0  bp: 000000400d3504f0  bx: 000000400d352700
  dx: 0000000000000000  ax: 0000000000000000  cx: 0000000000000027  sp: 000000400d3502a0
  ip: 000000400aaaf18b efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
 trp: ffffffffffffffff msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.

I'm using Apple M1, but having no issues running it locally.

Edit: No issues when running with Binder and Azure. Seems to be a problem related to Docker and Apple Silicon.

jonmmease commented 3 years ago

Hi @polakowo, thanks for the report. I haven't seen this before, but the error message includes: Check failed: sandbox::ThreadHelpers::IsSingleThreaded().

So one idea is to add the --single-process chromium flag. Here's general info in using custom chromium flags in kaleido (https://github.com/plotly/Kaleido/wiki/Customizing-Chromium-Flags). Here's what you can try in particular:

import plotly.io as pio
pio.kaleido.scope.chromium_args += ("--single-process",) 
polakowo commented 3 years ago

@jonmmease thank you, this worked!