简体   繁体   中英

How to send return value to JS without stopping Python function

I am using the eel module to communicate with Javascript (My Web UI). I have a loading screen while the python script is running. So I need my user to know what is the progress in python side while in loading screen.

So there is a function myfunction which is called from Web UI through Javascript. This function has around 5 stages. So I need to return the stage that the execution is currently in to be displayed on my loading screen. Now I only use a return 'Done' at the end of all stages. So that once all stages is finished the return value is displayed

eel.myfunction()(function (ret){
$('#status').text(ret)
})

How can I send a return value from python without stopping the function?

Best thing to do is to have a function 'setLoadingFase' in you javascript and expose it to eel. From the python you can call this function with the new loading fase you're in.

JS:

setLoadingFase(currentFase){
    console.log(currentFase)
}
eel.expose(setLoadingFase, 'set_loading_fase')

python:

@eel.expose
def load_program():
    ...
    eel.set_loading_fase("done with loading 1")
    ...
    eel.set_loading_fase("done with loading 2")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM