本文介绍了如何在cefpython中调用MessageLoopWork?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 cefpython 制作了一个简单的屏幕外渲染器.

I made a simple offscreen renderer with cefpython.

我使用了cefpython.MessageLoop(),但是我想使用browser.GetFocusedFrame().ExecuteFunction执行javascript函数,该函数必须从主UI线程调用.

I used cefpython.MessageLoop() but I would like to execute a javascript function with browser.GetFocusedFrame().ExecuteFunctionwhich must be called from main UI thread.

是否可以在cefpython的消息循环中设置回调?

Is there a way to set a callback on cefpython's message loop?

或者我可以使用MessageLoopWork,但是我不知道怎么做.我试图在一个单独的线程中调用它,但是它不起作用:

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

我收到以下错误:

[0324/174806:ERROR_REPORT:context.cc(146)] Check failed: false. called on invalid thread

推荐答案

使用cefpython.PostTask()函数将任务发布到各种CEF线程上.请参阅: https://code.google.com/p/cefpython/wiki/cefpython#PostTask_(int_threadId,_object_func_[,args..])_(void)和问题61.自31.0版开始可用.

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.

wxpython.py示例显示了如何将计时器与MessageLoopWork()和MessageLoop()一起使用.

The wxpython.py example shows how to use both timer with MessageLoopWork() and MessageLoop().

这篇关于如何在cefpython中调用MessageLoopWork?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 21:18