如何检查我的 Bokeh Server 应用程序是否已完全加载和渲染?

How to check if my Bokeh Server Application is completely loaded and rendered?(如何检查我的 Bokeh Server 应用程序是否已完全加载和渲染?)
本文介绍了如何检查我的 Bokeh Server 应用程序是否已完全加载和渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

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

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

它检查散景端口是否仍然关闭.但是元素可能没有加载并完全加载

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 建议验证散景页面是否使用 MutationObserver,但我没用过.

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 应用程序是否已完全加载和渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)