javascriptpythonasynchronousmultiprocessingeel

calling multiple python functions while some of them still not finished


I'm using eel to write a program and I have an issue

let's say we have this python code:

import eel

eel.init('web')

run =1
@eel.expose
def start():
    global run 
    while run:
        print("loop")

@eel.expose
def stop():
    global run 
    run =0
    print("stopped................................")

if __name__ == '__main__':
    eel.start('index.html')

and the html and js part is like this:

<html>
  <head>
    <script type="text/javascript" src="/eel.js"></script>
    <title>doc</title>
  </head>
  <body>
    <input type="button" onclick="startJs()" value="start">
    <input type="button" onclick="stopJs()" value="stop">
    <script>
      function startJs(){
        eel.start();
      }

      function stopJs(){
        eel.stop()
      }
    </script>
  </body>
</html>

so I want to first call python start function using javascript then stop it by the stop function

but, when I hit start, the stop function(from python) doesn't work at all!!!

I think it's because, it's still processing the start function, but can I double cross it?

can anyone help please?


Solution

  • Hi it's me talking to myself :_)

    I've added a eel.sleep(0.001) in while loop and the stop function worked :)