python - Flask 脚本作为切换服务
问题描述
我有一个永远运行循环的函数:
def some_function():
while True:
#some tasks here
我需要编写一个 Flask 脚本,这样当请求到来时,如果该函数停止,则应该开始执行该函数,反之亦然。因此,例如,对于这样的函数:
def some_function():
count = 0
while True:
print(count)
sleep(5)
我需要这样的东西:
@app.route('/')
def toggle():
if function_isnt_running():
start_function_execution()
return Response('Started')
else:
stop_function_execution()
return Response('Stopped')
解决方案
推荐阅读
- opencl - 如何在 OpenCL 中分配本地工作项大小
- php - 如何使用 jquery、ajax 和 php 在数据库中保存图像文件 (BLOB)
- pandas - 安装 python(3.6.6) 模块 pandas-0.24.2 时 Numpy 失败。在 AIX 7.1.0.0 上
- sql-server - 按年和月进行表分区
- python - 无法在 numpy 数组中分配
- html - 使用 CSS Grid 重现 flex 的“换行”
- google-cloud-data-fusion - 运行简单数据融合管道以从 Bigquery 导出数据并写入 GCS 时出现连接超时错误
- php - 如何在php中显示成功从mysql中删除记录的消息
- validation - 一个人可以有空名字吗?
- javascript - PIE 切片的颜色不是唯一的