flask运行循环并在htm中更新其输出

2024-09-30 02:34:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在构建flask应用程序,以便实现以下功能:

  1. 访问“localhost/run”(ajax),它在flask中运行一个循环,循环使用print('')打印输出。你知道吗
  2. html文本区域不断从项目1获得输出(这里可能是ajax“localhost/update”)你知道吗
  3. 访问“localhost/stop”(ajax),停止item 1的循环

我搜索了很多关于多线程,进程,芹菜,但似乎我找不到一个解决方案来实现以上。你知道吗

到目前为止的最新情况:

pp=None
@simple_page.route('/stop')
def stopApp():
    pp.join()

@simple_page.route('/run')
def runApp():
    pp = Process(target=theAppLoop, args=('',))
    pp.daemon = True
    pp.start()

@simple_page.route('/update')
def updateMonitor():
    #return pp's print('')?

def theAppLoop(s):
    while True:
        run_cycle()

def run_cycle():
    #call others func and those func will do print('')

Tags: runtruelocalhostflaskdefpageupdateajax

热门问题