Javascript and threading

182 views
Skip to first unread message

ad...@docurated.com

unread,
Aug 12, 2014, 7:38:38 PM8/12/14
to cefp...@googlegroups.com
Hi Czarek,

As you know, we're using CEFPython in a WXPython application, using a method almost identical to the one your example uses.

We're using Javascript functions that bind to Python code through JavascriptBindings, and we're noticing that the Python code called through Javascript ends up executing on a UI thread, so long-running functions tie up the UI.

Is there a way around this? Obviously we could just create a new thread in Python but we're hoping that there's some way to avoid that.

Thank you very much for the great library.

Adam

Czarek Tomczak

unread,
Aug 13, 2014, 1:42:54 AM8/13/14
to
Regarding the new thread solution. Python uses GIL (global interpreter lock) that allows only one native thread to be running python code at the same time. Be aware that there is a 10ms wx timer running on the UI thread that calls CEF message loop work (it must be called on application main thread). I don't know if this is going to be a problem, as I don't know how exactly python threading works. I've always used only the multiprocessing module. 

There is ApplicationSettings."multi_threaded_message_loop" that tells CEF to run message loop on its own separate thread. You could try that to avoid blocking UI. I haven't yet played with that option so can't tell you what to expect. I think CEF creates its own separate UI thread, so now all mentions in docs about function being required to be called on UI thread refer to that thread. Most of CEF client handler callbacks would now get called on that new thread. That should include python functions called from javascipt as well. However, this option is not yet officially supported by cefpython* (by CEF it is), so there might be bugs. If you find any, please report it in the CEF Python Issue Tracker and we might do something about it.

In 31.0 release there is new function available cefpython.PostTask with which you can run tasks on various CEF threads. The browser process threads are: TID_UI, TID_DB,  TID_FILE, TID_FILE_USER_BLOCKING, TID_CACHE, TID_IO. See the cefpython module wiki page.

* - EDITS

Czarek Tomczak

unread,
Aug 13, 2014, 4:08:07 AM8/13/14
to cefp...@googlegroups.com
Created Issue 133 "Example of using multi threaded CEF message loop":
Reply all
Reply to author
Forward
0 new messages