我正在使用 python 输出 html。到目前为止运行良好,但是我现在需要运行一个很长的 python 函数。鉴于输出 html 的方法使用 python return 语句。当我运行长脚本时,直到长脚本完成编译后才会输出 HTML。输出一些 HTML 的最佳方法是什么 - 例如在编译漫长的过程时“正在加载 - 请稍候..”?我尝试使用两个 python 脚本和 subprocess 模块执行与下面的代码片段类似的操作。
主.py
import subprocess
import waitScript
def loadingPage():
loadingOutput = """
<div class="container-fluid">
<h1> Please wait - Loading files..</h1>
<div class="spinner-border" role="status">
<span class="sr-only"></span>
</div>
</div>
"""
subprocess.call(['python', 'waitScript.py'])
return(loadingOutput)
这里是被调用的 python 脚本 - 它只是等待 15 秒。
waitScript.py
import time
time.sleep(15)
我对 subprocess 模块的误解是它能够在后台运行 waitScript,而 main.py 仍然能够返回 html。但每次好像都要等15秒然后返回html。
有什么办法可以在耗时的脚本仍在运行之前输出或返回html?我开始认为有一个更好的模块可以实现我想要实现的目标,但到目前为止还没有找到一个。