传输大数据时,CEFPython窗口在没有警告的情况下关闭

问题描述 投票:1回答:1

我正在尝试创建这个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 \站点包\ cefpython3” --lang = EN-US - 禁用GPU着色器,磁盘缓存--gpu - 偏好= KAAAAAAAAACAA4CAAQAAAAAAAAAAAGAAEAAAAAAAAAAAAAAAAAAAACgAAAAEAAAAIAAAAAAAAAAoAAAAAAAAADAAAAAAAAAAOAAAAAAAAAAQAAAAAAAAAAAAAAAKAAAAEAAAAAAAAAAAAAAACwAAABAAAAAAAAAAAQAAAAoAAAAQAAAAAAAAAAEAAAALAAAA --locales-DIR-路径=“<> \ 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上搜索:// 122.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 - log-severity = info --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,参数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

javascript python chromium-embedded cefpython
1个回答
0
投票

Javascript bindinsgs不应该用于传输大数据。要发送大数据,请改用http请求。基本上要么使用AJAX请求并运行内部应用内Web服务器,要么使用资源处理程序,它允许在不运行Web服务器的情况下处理请求。

请参阅教程文档>“Javascript集成”>“使用http请求进行通信”部分(单击链接后向下滚动):

https://github.com/cztomczak/cefpython/blob/master/docs/Tutorial.md#javascript-integration

您可以尝试使用javascript绑定以较小的部分发送数据,但使用请求将更好地执行。

检查发送数据时应用内存如何激增。在Linux上使用进程监视器,在Windows上使用进程管理器。

要找出发送200 MB数据时失败的内容,请调试app以获取堆栈跟踪。如果使用Linux,则下载libcef.so,其中包含标记为Releases页面的调试符号,例如: V66-上游。用cefpython3包替换原来的libcef.so。 GDB命令可以在这里找到:

https://github.com/cztomczak/cefpython/blob/master/docs/Knowledge-Base.md#python-crashes-with-segmentation-fault---how-to-debug

© www.soinside.com 2019 - 2024. All rights reserved.