from flask import current_app
app= current_app._get_current_object()
thr = Thread(target=run_pssh, args=(app,ip_list, username, password, oss_path, remote_path, id_list, script_type))
thr.start()
def run_pssh(app,ips, username, password, oss_path, remote_path, id_list,script_type):
with app.app_context():
在我的接口中如果直接用app会报重复引用,必须使用
app= current_app._get_current_object()
然后再我的函数中添加一个参数app 把app加进去,并在函数中用context上下文。
就实现异步了,这里使用进程会报错。
文章讲述了在Flask应用中如何避免直接使用`app`导致的重复引用错误,通过使用`current_app._get_current_object()`获取当前应用对象并作为参数传递给异步函数run_pssh,确保在函数内部正确使用context上下文处理并发问题。
483

被折叠的 条评论
为什么被折叠?



