[英]Multiprocess can not work in flask when I deploy flask to server by using flask + uwsgi + nginx
我正在使用 Flask + uwsgi + nginx 在服務器上部署網站。
在flask中,我的代碼在下面,這里是我想要設計的:每次點擊run model時,它會在另一個進程中運行一個模型,但界面會立即鏈接到等待界面。
train_dataset.status = status
db.session.commit()
text = 'Start training your models, please wait for a while or check results several hours later'
# would run a model in another process
task = Process(target=start_train, args=(app.config['UPLOAD_FOLDER'], current_user.id, p.id, p.task), name="training.exe")
task.start()
print(task.pid, task.name)
session[f"{project_name}_train"] = task.pid
# in the meanwhile, link to waiting interface
return render_template('p_computeview.html', project_name=project_name, text=text,
status=status, p=p, email=email, not_identify=not_identify)
當我在本地開發環境中測試時
app.run()
沒關系,當我點擊運行模型時,界面只是鏈接到等待界面,我可以看到模型運行日志。 但是當我部署到服務器時,我選擇了uwsgi + nginx + flask。
在uwsgi.ini中,我已經指定了進程
processes=2
threads=5
但是當我點擊運行模型時,界面還是,沒有鏈接到等待界面,但是可以看到模型運行日志,建模完成后,界面會鏈接到等待界面(證明Process功能沒有在職的 ??)
我的服務器有 2 個 CPU,所以我認為它可以支持多進程
有人能幫我嗎 ? 我猜 uwsgi 或 nginx 有問題?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.