作者mchik (chen)
看板Python
标题[问题] Python Flask问题
时间Fri Sep 3 15:26:09 2021
我使用POST request透过index()函式,接收一个目标温度资料(target_temperature),
我们可以知道request_data[ 'target_temperature' ]是我目标温度的值。想请问如果我
要将此资料给其他函式使用(例如:job()),想在job()函式中,印出使用index()函式读取
到资料,想请问大家要如何做?谢谢大家的帮忙!
from flask import Flask, request, jsonify
import time
import threading
request_data = {'target_temperature':0}
def job():
for i in range(3):
print(data['target_temperature'])
t = threading.Thread(target = job)
t.start()
app = Flask(__name__)
@app.route('/', methods=['POST'])
def index():
request_data = request.get_json(force=True)
return jsonify({'target_temperature':request_data['target_temperature']})
if __name__ == '__main__':
app.run(host="0.0.0.0", port=9090)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 90.197.48.235 (英国)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1630653971.A.536.html
1F:推 lycantrope: 用queue 09/03 15:40
好的,感谢
※ 编辑: mchik (46.233.83.54 英国), 09/05/2021 21:08:04