BLCL的博客小馆

标签 · Flask

首页

关于

归档

loading..
PythonFlask

Flask中如何嵌套启动子线程?

如果你在Flask中启动过子线程,然后在子线程中读写过g对象或者尝试从request对象中读取url参数,那么,你肯定对下面这个报错不陌生:RuntimeError: Working outside of request context..例如下面这段Flask代码:123456789101112131415import threadingfrom flask import Flask, requestapp = Flask(__name__)def inner_func(): doc_id = request.args.get('doc_id', '') print(f'用户ID为:{doc_id}')@app.route('/start_thread')def start_thread()..

更多