[问题] Python Flask问题

楼主: mchik (chen)   2021-09-03 15:26:09
我使用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)
作者: lycantrope (阿宽)   2021-09-03 15:40:00
用queue

Links booklink

Contact Us: admin [ a t ] ucptt.com