Please be informed that the Eel package recommends two ways of regaining return values from the other side of the app, which helps keep the code concise.
To stop hanging permanently on the Python side, a timeout has been set in place for attempting to obtain values from the JavaScript side, which defaults to 10000 milliseconds (10 seconds). This can be substituted with the _js_result_timeout argument to eel.init. There is no similar timeout on the JavaScript side.
Say for instance, if we have the following method defined and displayed in
eel.expose(js_random);
function js_random() {
return Math.random();
}
#we can retrieve random values from the Javascript side like so:
def print_num(n):
print('Got this from ', n)
# Call Javascript function, and pass explicit callback function
eel.js_random()(print_num)
# Do the same with an inline lambda as the callback
eel.js_random()(lambda n: print('Got this from ', n))
(It works exactly the same the other way around).
Join this Python Training course now if you want to gain more knowledge in Python.