我正在尝试创建此 python 绑定到我创建的 electronjs 应用程序,其中 python 部分用于分析数据,并将结果(python 字典)传递给 Web 浏览器以进行可视化。对于少量数据,这一切都像一个魅力,但是当我试图传递一个大的结果字典(~200MB)时,窗口被创建了,但是在终端中没有警告就关闭了(我无法检查 devtool),虽然有似乎是一个在后端运行的子进程。这个问题发生在 Windows 和 Ubuntu 机器上,非常感谢您的帮助。
这是我的代码:
def view(data):
config = data
settings = {
"debug": True,
"log_severity": cef.LOGSEVERITY_INFO,
"log_file": "debug.log",
}
cef.Initialize(settings=settings)
browser_setting = { "file_access_from_file_urls_allowed":True,\
"universal_access_from_file_urls_allowed": True,\
"web_security_disabled":True}
browser = cef.CreateBrowserSync(url='file://' + os.path.realpath("index_cefpython.html"),
window_title="Javascript Bindings", settings = browser_setting)
browser.SetClientHandler(LoadHandler(config))
bindings = cef.JavascriptBindings()
browser.SetJavascriptBindings(bindings)
cef.MessageLoop()
del browser
cef.Shutdown()
return
class LoadHandler(object):
def __init__(self, config):
self.config = config
def OnLoadEnd(self, browser, **_):
browser.ExecuteFunction("defineData", self.config)
在 JS 方面,我有:
<script type="text/javascript">
function defineData(datainput){
console.log("start")
data = datainput;
Main();
}
</script>
这是终端中打印的所有消息:
[0312/104311.439:INFO:cefpython_app.cpp(199)] [浏览器进程] OnBeforeChildProcessLaunch() 命令行:"<>\Anaconda3\lib\site-packages\cefpython3\subprocess" --type=gpu-process --no -sandbox --locales-dir-path="<>\Anaconda3\lib\site-packages\cefpython3\locales" --log-file=debug.log --log-severity=info --resources-dir-path= "<>\Anaconda3\lib\site-packages\cefpython3" --lang=en-US --disable-gpu-shader-disk-cache /prefetch:2
[0312/104311.440:INFO:cef_log.cpp(8)] [浏览器进程] 开关已设置,忽略:disable-gpu-shader-disk-cache
[0312/104311.440:INFO:cefpython_app.cpp(199)] [浏览器进程] OnBeforeChildProcessLaunch() 命令行:"<>\Anaconda3\lib\site-packages\cefpython3\subprocess" --type=gpu-process --no -sandbox --locales-dir-path="C:\Users\Xiangyun\Anaconda3\lib\site-packages\cefpython3\locales" --log-file=debug.log --log-severity=info --resources- dir-path=" <>\Anaconda3\lib\site-packages\cefpython3" --lang=en-US --disable-gpu-shader-disk-cache --gpu-preferences=KAAAAAAAAAACAA4CAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ="<>\Anaconda3\lib\site-packages\cefpython3\locales" --log-file=debug.log --log-severity=info --resources-dir-path="<>\Anaconda3\lib\site-packages\cefpython3" --lang=en-US /prefetch:2
[0312/104311.473:INFO:cef_log.cpp(8)] [浏览器进程] CreateBrowserSync() 调用
DevTools 监听 ws://127.0.0.1:59232/devtools/browser/abaff316-3b5c-4647-8af3-c7c521146d08 [0312/104311.473:INFO:cef_log.cpp(8)] [浏览器进程] navigateUrl: file:// ///<>/index_cefpython.html
[0312/104311.475:INFO:cef_log.cpp(8)] [浏览器进程] CefBrowser::CreateBrowserSync()
[0312/104311.493:INFO:cef_log.cpp(8)] [浏览器进程] GetPyBrowser(): 创建新的 PyBrowser, browserId=1
[0312/104311.516:INFO:cefpython_app.cpp(199)] [浏览器进程] OnBeforeChildProcessLaunch() 命令行:"<>\Anaconda3\lib\site-packages\cefpython3\subprocess" --type=renderer --no-sandbox --service-pipe-token=C31AF08C64F1883299C21D068EF5263C --lang=en-US --locales-dir-path=<>\Anaconda3\lib\site-packages\cefpython3\locales" --log-file=debug.log --日志严重性=信息 --resources-dir-path="<>\Anaconda3\lib\site-packages\cefpython3" --disable-gpu-shader-disk-cache /prefetch:1
[0312/104311.528:INFO:cef_log.cpp(8)] [浏览器进程] GetPyFrame(): 底层框架还不存在: browserId = 1, frameId = -4
[0312/104311.529:INFO:cef_log.cpp(8)] [浏览器进程] GetPyFrame(): 底层框架还不存在: browserId = 1, frameId = -4
[0312/104311.531:INFO:cef_log.cpp(8)] [浏览器进程] CefBrowser::CreateBrowserSync() 成功
[0312/104311.532:INFO:cef_log.cpp(8)] [浏览器进程] CefBrowser 窗口句柄 = 595526
[0312/104311.533:INFO:cef_log.cpp(8)] [浏览器进程] GetPyFrame(): 底层框架还不存在: browserId = 1, frameId = -4
[0312/104311.534:INFO:cef_log.cpp(8)] [浏览器进程] SendProcessMessage(): message=DoJavascriptBindings, arguments size=1
[0312/104311.534:INFO:cef_log.cpp(8)] [浏览器进程] MessageLoop()
[0312/104311.612:INFO:client_handler.cpp(40)] [浏览器进程] OnProcessMessageReceived(): OnContextCreated
[0312/104311.613:INFO:cef_log.cpp(8)] [浏览器进程] V8ContextHandler_OnContextCreated()
[0312/104311.614:INFO:cef_log.cpp(8)] [浏览器进程] GetPyFrame(): 创建新的 PyFrame, frameId=2