How to check if my Bokeh Server Application is completely loaded and rendered?

后端 未结 1 386
迷失自我
迷失自我 2021-01-13 10:02

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



        
1条回答
  •  无人及你
    2021-01-13 10:39

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

    Workaround 1

    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);
    

    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);  
    

    Workaround 3

    Finally I found another workaround to check if all the elements are completely rendered. The answer is in 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);
    };
    

    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.

    0 讨论(0)
提交回复
热议问题