调用多个 python 函数,其中一些函数仍未完成

calling multiple python functions while some of them still not finished

我正在使用 eel 编写程序,但遇到了问题

假设我们有这个 python 代码:

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

而html和js部分是这样的:

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

所以我想先使用 javascript 调用 python 启动函数,然后使用停止函数

停止它

但是,当我点击开始时,停止功能(来自 python)根本不起作用!!!

我想是因为,它还在处理启动函数,但是我可以双交叉吗?

有人可以帮忙吗?

嗨,这是我在自言自语:_)

我在 while 循环中添加了一个 eel.sleep(0.001) 并且停止函数起作用了:)