How to call MessageLoopWork in cefpython?

烂漫一生 提交于 2020-01-21 13:48:49

问题


I made a simple offscreen renderer with cefpython.

I used cefpython.MessageLoop() but I would like to execute a javascript function with browser.GetFocusedFrame().ExecuteFunctionwhich 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

回答1:


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().



来源:https://stackoverflow.com/questions/29238431/how-to-call-messageloopwork-in-cefpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!