我剛開始燒瓶,我正在製作一個服務器應用程序,它將處理一些請求,現在對於POST請求部分它有一個過程,這將需要一些時間意味着我將不得不讓用戶留在移動應用程序中,等待我回復他發送的第一個POST請求。燒瓶返回「好」給用戶並處理數據
是否有某種方式可以將OK
例如返回到移動應用程序並在後臺處理數據?
什麼我迄今想到會是這樣的: -
if request.method=='POST':
#signal another process (another python file for example) to start with parameters from the request
return "OK"
但我不知道這是最好的做法,任何其他的想法?
編輯
以下安裝芹菜我已經下載的建議和安裝在Windows上使用Redis的一起。我有一個經紀人工人芹菜運行,但我得到下面當我嘗試發出POST請求:
TypeError: ExtractFeatures() takes exactly 2 arguments (1 given)
我塞萊拉與Redis的配置:
from flask import Flask
from celery import Celery
app = Flask(__name__)
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
,爲ExtractFeatures()
功能:
def ExtractFeatures(JsonRecieved):
#testing for now sleep for 5 seconds to make sure code executes this
#function parallel and finishes the request handling
time.sleep(5)
print("finished Extracting Features")
爲POST請求:
@app.route('/PostPhotos',methods=['POST'])
def api_PostPhotos():
if request.method=="POST":
ExtractFeatures.delay(request.json)
return("finished request")
我的期望是在「完成提取特徵」之前打印「完成的請求」,但是我得到上面顯示的錯誤。
你需要一些東西像芹菜。 –
@DanielRoseman我添加了一個新的編輯,如果你可以幫助我 –