本文介绍了如何检查我的Bokeh Server应用程序是否已完全加载并呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to integrate my Bokeh Server Application in Electron. So what I did is to run bokeh server using python-shell like this

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

这里的问题是窗口永远不会弹出,因为电子无法检测到服务器已加载.

The problem here is that the window never pops up because electron does not detect the server as loaded.

推荐答案

我发现了很多解决方法.我仍在等待最终解决方案.

I have found a bunch of workarounds. I am still waiting for the final solution.

所以我必须添加此setTimeout作为解决方法.如果我不使用此页面,则该页面将永远卡住.

So I had to add this setTimeout as a workaround. If I do not use this the page would be stuck forever.

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

解决方法2

它检查bokeh端口是否仍然关闭.但是元素可能未加载且未完全加载

Workaround 2

It checks if the bokeh port is still closed. But the elements may be not loaded and completely loaded

var portscanner = require('portscanner')
var _checkServerStatus = setInterval(function() {
  portscanner.checkPortStatus(5006, '127.0.0.1', function(error, status) {
    if (status == 'open') {  // status = 'open' or 'close'
        clearInterval(_checkServerStatus);
        console.log('Server running');
        mainWindow.loadURL(bokehUrl);
    }
  });
}, 100);

解决方法3

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

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问题,在该问题中,作者要求在以下情况下调用回调散景已完全加载并渲染.用户foobarbecue建议验证是否使用,但我从未使用过.

Workaround 4

There is a GH issue where where the writer ask for calling a callback when bokeh is completely loaded and rendered. The user foobarbecue suggests to verify if the bokeh page is rendered with MutationObserver, but I have never used it.

这篇关于如何检查我的Bokeh Server应用程序是否已完全加载并呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:35