GTK2 example hangs on CreateBrowserSync if window has no icon

164 views
Skip to first unread message

nicola...@gmail.com

unread,
Apr 16, 2017, 7:26:05 AM4/16/17
to CEF Python
I found the GTK2 example wouldn't work if I copied gtk2.py to a different directory. Eventually I traced this to cef.CreateBrowserSync, but only when the line that sets the window's icon (self.main_window.set_icon_from_file) isn't called. Is this a known limitation in CEF or a limitation in my setup?

Currently using Ubuntu 16.04.2 + XFCE (Not Xubuntu, though) with libgtk 2.24.30-1ubuntu1. Here's the diff for my gtk2.py file:

diff --git a/examples/gtk2.py b/examples/gtk2.py
index 99d7cc1..0afabf8 100644
--- a/examples/gtk2.py
+++ b/examples/gtk2.py
@@ -86,7 +86,7 @@ class Gtk2Example:
self.main_window.set_title('GTK 2 example (PyGTK)')
icon = os.path.join(os.path.dirname(__file__), "resources", "gtk.png")
if os.path.exists(icon):
- self.main_window.set_icon_from_file(icon)
+ pass #self.main_window.set_icon_from_file(icon)
self.main_window.realize()

self.vbox = gtk.VBox(False, 0)
@@ -110,8 +110,10 @@ class Gtk2Example:
size = self.main_window.get_size()
rect = [0, 0, size[0], size[1]]
windowInfo.SetAsChild(self.get_window_handle(), rect)
+ print "HERE"
self.browser = cef.CreateBrowserSync(windowInfo, settings={},
url="https://www.google.com/")
+ print "THERE"
self.browser.SetClientHandler(LoadHandler())

def get_window_handle(self):

Czarek Tomczak

unread,
Apr 16, 2017, 7:46:20 AM4/16/17
to CEF Python
It works fine for more. What exactly do you mean by "wouldn't work", what is the error? Run example with the --debug flag and attach the debug.log file from that run (when the issue occurs).

nicola...@gmail.com

unread,
Apr 16, 2017, 8:17:22 AM4/16/17
to CEF Python
Thanks for checking, Czarek. I'd assume this is some weirdness in my setup then. By "not working" I mean what I wrote in the subject: CreateBrowserSync never returns. Running with --debug I do see some error messages which are not there when the example works fine. Not sure how to troubleshoot further. This is the log of a failed run:

laptus@newptus:~/src/cefpython/examples$ python gtk2.py --debug
[gtk2.py] CEF Python 56.1
[gtk2.py] Python 2.7.12 64bit
[gtk2.py] GTK 2.24.30
[gtk2.py] Message loop mode: TIMER
[CEF Python] Initialize() called
[CEF Python] CefExecuteProcess(): exitCode = -1
[CEF Python] CefInitialize()
[CEF Python] App_OnBeforeCommandLineProcessing_BrowserProcess()
[CEF Python] Command line string for the browser process: --browser-subprocess-path=/usr/local/lib/python2.7/dist-packages/cefpython3/subprocess --no-sandbox --lang=en-US --log-file=/usr/local/lib/python2.7/dist-packages/cefpython3/debug.log --log-severity=warning --resources-dir-path=/usr/local/lib/python2.7/dist-packages/cefpython3 --locales-dir-path=/usr/local/lib/python2.7/dist-packages/cefpython3/locales --remote-debugging-port=64107
[CEF Python] BrowserProcessHandler_OnBeforeChildProcessLaunch()
[CEF Python] WindowUtils::IsWindowHandle() not implemented (always True)
[CEF Python] CreateBrowserSync() called
[CEF Python] navigateUrl: https://www.google.com/
[CEF Python] CefBrowser::CreateBrowserSync()
[CEF Python] X error received: type 0, serial 101, error_code 3, request_code 1, minor_code 0

[CEF Python] X error received: type 0, serial 102, error_code 3, request_code 2, minor_code 0

[CEF Python] X error received: type 0, serial 103, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 104, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 106, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 107, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 146, error_code 3, request_code 1, minor_code 0

[CEF Python] X error received: type 0, serial 148, error_code 3, request_code 131, minor_code 46

[CEF Python] X error received: type 0, serial 149, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 150, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 151, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 152, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 153, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 155, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 274, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 276, error_code 3, request_code 129, minor_code 1

[CEF Python] X error received: type 0, serial 284, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 285, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 290, error_code 3, request_code 18, minor_code 0

[CEF Python] X error received: type 0, serial 291, error_code 3, request_code 8, minor_code 0


---------------------------------

And a log of a successful run:

laptus@newptus:~/src/cefpython/examples$ python gtk2.py --debug
[gtk2.py] CEF Python 56.1
[gtk2.py] Python 2.7.12 64bit
[gtk2.py] GTK 2.24.30
[gtk2.py] Message loop mode: TIMER
[CEF Python] Initialize() called
[CEF Python] CefExecuteProcess(): exitCode = -1
[CEF Python] CefInitialize()
[CEF Python] App_OnBeforeCommandLineProcessing_BrowserProcess()
[CEF Python] Command line string for the browser process: --browser-subprocess-path=/usr/local/lib/python2.7/dist-packages/cefpython3/subprocess --no-sandbox --lang=en-US --log-file=/usr/local/lib/python2.7/dist-packages/cefpython3/debug.log --log-severity=warning --resources-dir-path=/usr/local/lib/python2.7/dist-packages/cefpython3 --locales-dir-path=/usr/local/lib/python2.7/dist-packages/cefpython3/locales --remote-debugging-port=60650
[CEF Python] BrowserProcessHandler_OnBeforeChildProcessLaunch()
[CEF Python] WindowUtils::IsWindowHandle() not implemented (always True)
[CEF Python] CreateBrowserSync() called
[CEF Python] navigateUrl: https://www.google.com/
[CEF Python] CefBrowser::CreateBrowserSync()
[CEF Python] GetPyBrowser(): create new PyBrowser, browserId=1
[CEF Python] BrowserProcessHandler_OnBeforeChildProcessLaunch()
[CEF Python] CefBrowser::CreateBrowserSync() succeeded
[CEF Python] Command line string for the zygote process: /usr/local/lib/python2.7/dist-packages/cefpython3/subprocess --type=zygote --no-sandbox --lang=en-US --locales-dir-path=/usr/local/lib/python2.7/dist-packages/cefpython3/locales --log-file=/usr/local/lib/python2.7/dist-packages/cefpython3/debug.log --log-severity=warning --resources-dir-path=/usr/local/lib/python2.7/dist-packages/cefpython3
[gtk2.py] LoadHandler.OnLoadStart: keyboard focus fix (Issue #284)
[CEF Python] Renderer: OnContextCreated()
[CEF Python] Browser: OnProcessMessageReceived(): OnContextCreated
[CEF Python] V8ContextHandler_OnContextCreated()
[0416/140841.607403:WARNING:quota_manager.cc(1833)] Create directory failed for path
[0416/140841.608137:WARNING:quota_manager.cc(1833)] Create directory failed for path

Czarek Tomczak

unread,
Apr 16, 2017, 8:56:34 AM4/16/17
to CEF Python
Have you made any other modifications to the example?
What does self.get_window_handle() return before calling CreateBrowserSync?

nicola...@gmail.com

unread,
Apr 16, 2017, 9:00:13 AM4/16/17
to CEF Python
On Sunday, 16 April 2017 14:56:34 UTC+2, Czarek Tomczak wrote:
> Have you made any other modifications to the example?

No modifications (I can trigger this problem, for example, by removing the icon file).

> What does self.get_window_handle() return before calling CreateBrowserSync?

Something that looks like a reasonably valid handle (69206019, if that's important). If I run the example twice, one triggering the problem and the other without, the number is the same.

Czarek Tomczak

unread,
Apr 16, 2017, 9:00:48 AM4/16/17
to CEF Python
The errors in logs suggest something is wrong with X11 window. Are you calling main_window.realize()?

Try to show window before browser is embedded and see if it makes any difference:

self.vbox.show()
self.main_window.show()
self.embed_browser()

nicola...@gmail.com

unread,
Apr 16, 2017, 9:08:23 AM4/16/17
to CEF Python
> Are you calling main_window.realize()?
Yes

> Try to show window before browser is embedded and see if it makes any difference:

That seems to work! Doing self.embed_browser() after show()ing the windows indeed fixes (or works around?) the problem. Any idea why? Thanks Czarek!

Czarek Tomczak

unread,
Apr 16, 2017, 9:12:07 AM4/16/17
to CEF Python
Looks like a race condition in GTK/X11. In some other examples like wxpython.py on Linux it is required to show window before embedding browser.

Czarek Tomczak

unread,
Apr 16, 2017, 9:16:59 AM4/16/17
to CEF Python

Czarek Tomczak

unread,
Apr 16, 2017, 12:02:42 PM4/16/17
to CEF Python
Btw. Nicolas, nice mustache on github, you look like a real gentleman :)

nicola...@gmail.com

unread,
Apr 17, 2017, 3:46:31 AM4/17/17
to CEF Python
Lol, thanks. It's the mustache that gives me super-powers to find weird race conditions.

Czarek Tomczak

unread,
Apr 17, 2017, 5:06:14 AM4/17/17
to CEF Python
Awesome :)
Reply all
Reply to author
Forward
0 new messages