I made a simple offscreen renderer with cefpython.
I used cefpython.MessageLoop()
but I would like to execute a javascript function with browser.GetFocusedFrame().ExecuteFunction
which must be called from main UI thread.
Is there a way to set a callback on cefpython's message loop?
Alternatively I could use MessageLoopWork
, but I don't know how. I tried to call it in a separate thread but it does not work:
import threading
def main_loop():
cefpython.MessageLoopWork()
threading.Timer(0.01, main_loop).start()
threading.Timer(0.01, main_loop).start()
I get the following error:
[0324/174806:ERROR_REPORT:context.cc(146)] Check failed: false. called on invalid thread
Use the cefpython.PostTask() function to post tasks on various CEF threads. See: https://code.google.com/p/cefpython/wiki/cefpython#PostTask_(int_threadId,_object_func_[,args..])_(void) and Issue 61. It's available since version 31.0.
The wxpython.py example shows how to use both timer with MessageLoopWork() and MessageLoop().