問(wèn)題描述
我想將我的散景服務(wù)器應(yīng)用程序集成到 Electron 中.所以我所做的是像這樣使用 python-shell
運(yùn)行散景服務(wù)器
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()
})
這里的問(wèn)題是窗口永遠(yuǎn)不會(huì)彈出,因?yàn)?electron 沒(méi)有檢測(cè)到服務(wù)器已加載.
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.
所以我不得不添加這個(gè) setTimeout
作為解決方法.如果我不使用它,頁(yè)面將永遠(yuǎn)卡住.
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
它檢查散景端口是否仍然關(guān)閉.但是元素可能沒(méi)有加載并完全加載
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
最后我找到了另一種解決方法來(lái)檢查是否所有元素都已完全呈現(xiàn).答案在 這個(gè)問(wèn)題:
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
有一個(gè) GH 問(wèn)題,作者要求在該問(wèn)題時(shí)調(diào)用回調(diào)散景已完全加載和渲染.用戶 foobarbecue 建議驗(yàn)證散景頁(yè)面是否使用 MutationObserver,但我沒(méi)用過(guò).
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.
這篇關(guān)于如何檢查我的 Bokeh Server 應(yīng)用程序是否已完全加載和渲染?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!