如何检查我的Bokeh服务器应用程序是否已完全加载和呈现?

2024-10-16 17:26:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将我的Bokeh服务器应用程序集成到Electron中。所以我所做的就是使用python-shell来运行bokeh服务器

mainWindow = new BrowserWindow({
    width: 1000,
    height: 700,
    show: false,
})

var PythonShell = require('python-shell');
var options = {
    mode: 'text',
    pythonPath: 'python3',
    pythonOptions: ['-m'],
    scriptPath: '',
    args: ['serve','bokeh_project/']
};

PythonShell.run('bokeh', options, function (err, results) {
    if (err) throw err;
    console.log('results: %j', results);
});

mainWindow.loadURL('http://localhost:5006');

mainWindow.once('did-finish-load', () => {
    mainWindow.show()
})

这里的问题是窗口永远不会弹出,因为electron没有检测到服务器已加载。在


Tags: 服务器newvarshowbokehshellresults服务器应用程序
1条回答
网友
1楼 · 发布于 2024-10-16 17:26:32

我找到了一些解决办法。我仍在等待最后的解决办法。在

解决方法1

所以我不得不添加这个setTimeout作为一个解决方法。如果我不使用这个页面将永远被卡住。在

setTimeout(function () {
    mainWindow.show();
    mainWindow.loadURL('http://localhost:5006');
}, 3000);

解决方案2

它检查bokeh港是否仍然关闭。但是这些元素可能没有被加载并且完全加载

^{pr2}$

解决方法3

最后,我找到了另一个解决方法来检查是否所有元素都已完全呈现。答案在this question

oldLog = console.log;
console.log = function (message) {
    if(message.localeCompare('Bokeh items were rendered successfully') == 0){
        window.top.postMessage('show-bokeh-iframe', '*')
        console.log = oldLog;
    }
    oldLog.apply(console, arguments);
};

解决方法4

有一个GH issue,当bokeh完全加载和呈现时,编写器在其中请求调用回调。用户foobrake建议验证bokeh页面是否使用MutationObserver呈现,但我从未使用过它。在

相关问题 更多 >