cefpython crashes at process exit in PyThread code?

127 views
Skip to first unread message

Ivan Voras

unread,
Mar 31, 2017, 4:21:07 AM3/31/17
to CEF Python
Hi,

I have a strange problem when my process using cefpython crashes during shutdown, after QuitMessageLoop() has been called, with the following gdb backtrace:

(gdb) bt
#0  __new_sem_wait_fast (definitive_result=0, sem=0x0) at sem_waitcommon.c:135
#1  __new_sem_wait (sem=0x0) at sem_wait.c:26
#2  0x00000000005378f5 in PyThread_acquire_lock_timed () at ../Python/thread_pthread.h:352
#3  0x00000000005fe48a in new_threadstate (interp=0x0, init=init@entry=1) at ../Python/pystate.c:229
#4  0x0000000000455d3e in PyThreadState_New () at ../Python/pystate.c:244
#5  PyGILState_Ensure () at ../Python/pystate.c:810
#6  0x00007f026d5f4173 in LifespanHandler_OnBeforeClose () from /usr/local/lib/python3.5/dist-packages/cefpython3/cefpython_py35.so
#7  0x00007f026d7c6ad5 in LifespanHandler::OnBeforeClose(CefRefPtr<CefBrowser>) () from /usr/local/lib/python3.5/dist-packages/cefpython3/cefpython_py35.so
#8  0x0000000002b47c00 in ?? ()
#9  0x00007ffdf35c6b20 in ?? ()
#10 0x0000000003181628 in ?? ()
#11 0x00007f026d796ac2 in (anonymous namespace)::life_span_handler_on_before_close(_cef_life_span_handler_t*, _cef_browser_t*) () from /usr/local/lib/python3.5/dist-packages/cefpython3/cefpython_py35.so
#12 0x00007f0280f405f8 in _nl_current_default_domain () from /lib/x86_64-linux-gnu/libc.so.6



The code uses threads, but after I've disabled all the thread creation in my code, this problem persists.

At frame #5 above, it seems that GIL is somehow involved.

Can anyone shed some light into what could be happening? The only possibly-weird thing I'm doing is calling QuitMessageLoop() from the OnPaint() handler.

Czarek Tomczak

unread,
Mar 31, 2017, 4:36:40 AM3/31/17
to CEF Python
Run the script with --debug flag passed on command line and you should see debug info in console. Please paste it. Do you see anything strange there? How many times do you see "QuitMessageLoop()" in logs?

When you call QuitMessageLoop cefpython releases Python's GIL (thread related) before calling upstream CefQuitMessageLoop.

Ivan Voras

unread,
Mar 31, 2017, 4:41:35 AM3/31/17
to CEF Python
Is using the "--debug" flag the same as passing "debug": "true" in the argument to Initialise()? Because I don't see anything different.

I'm calling QuitMessageLoop() exactly once, and it crashes the first time. Here are the last lines from the log before it crashes:

[CEF Python] BrowserProcessHandler_OnBeforeChildProcessLaunch()
[CEF Python] BrowserProcessHandler_OnBeforeChildProcessLaunch()
[CEF Python] Switch already set, ignoring: disable-web-security
[CEF Python] Switch already set, ignoring: debug
[CEF Python] Switch already set, ignoring: ignore-gpu-blacklist
[CEF Python] BrowserProcessHandler_OnBeforeChildProcessLaunch()
[CEF Python] CreateBrowserSync() called
[CEF Python] navigateUrl: file:///home/ivoras/zvium/tests/resources/testrtanimation.html
[CEF Python] CefBrowser::CreateBrowserSync()
[CEF Python] GetPyBrowser(): create new PyBrowser, browserId=1
[CEF Python] BrowserProcessHandler_OnBeforeChildProcessLaunch()
[CEF Python] CefBrowser::CreateBrowserSync() succeeded
[CEF Python] MessageLoop()
[CEF Python] App: Command line string for the zygote process: /usr/local/lib/python3.5/dist-packages/cefpython3/subprocess --type=zygote --no-sandbox --lang=en-US --locales-dir-path=/usr/local/lib/python3.5/dist-packages/cefpython3/locales --log-file=/tmp/zvium_cef.log --log-severity=disable --resources-dir-path=/usr/local/lib/python3.5/dist-packages/cefpython3 --disable-web-security=true --debug=true --ignore-gpu-blacklist=true
[CEF Python] App: Renderer: OnContextCreated()
[CEF Python] App: Browser: OnProcessMessageReceived(): OnContextCreated
[CEF Python] V8ContextHandler_OnContextCreated()
[CEF Python] QuitMessageLoop()



Czarek Tomczak

unread,
Mar 31, 2017, 4:59:28 AM3/31/17
to CEF Python
Please try to create a smallest example possible that reproduces your issue and paste the code. There is a screenshot example on gist, however this wasn't probably tested with latest cefpython, so some modification might be required: https://gist.github.com/stefanbacon/7b1571d57aee54aa9f8e9021b4848d06

Czarek Tomczak

unread,
Mar 31, 2017, 5:01:26 AM3/31/17
to CEF Python
Here is updated screenshot example: https://pastebin.com/dBD8nL3t

Czarek Tomczak

unread,
Mar 31, 2017, 5:06:43 AM3/31/17
to CEF Python
The stack trace shows that the error occurs during OnBeforeClose event. This event might get called when calling CloseBrowser or Shutdown. So it must occur after the call to QuitMessageLoop.

cztomczak

unread,
Mar 31, 2017, 2:38:12 PM3/31/17
to CEF Python
Calling QuitMessageLoop in OnPaint screenshot example works just fine. However calling CloseBrowser in OnPaint is causing segmentation fault. Looks like you can't close browser in OnPaint event.

Ivan Voras

unread,
Apr 3, 2017, 7:10:03 AM4/3/17
to CEF Python
On Friday, 31 March 2017 20:38:12 UTC+2, cztomczak wrote:
Calling QuitMessageLoop in OnPaint screenshot example works just fine. However calling CloseBrowser in OnPaint is causing segmentation fault. Looks like you can't close browser in OnPaint event.


Thanks!

So, If I want to cleanly close everything and it should start from the OnPaint() event, what would you suggest needs to be done?

Czarek Tomczak

unread,
Apr 3, 2017, 7:39:41 AM4/3/17
to CEF Python
Call QuitMessageLoop in OnPaint. Call CloseBrowser after MessageLoop returns. Clear browser reference. Call Shutdown.
Reply all
Reply to author
Forward
0 new messages