[問題] Python Flask問題

看板Python作者 (chen)時間2年前 (2021/09/03 15:26), 編輯推噓1(100)
留言1則, 1人參與, 2年前最新討論串1/1
我使用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://www.ptt.cc/bbs/Python/M.1630653971.A.536.html

09/03 15:40, 2年前 , 1F
用queue
09/03 15:40, 1F
文章代碼(AID): #1XCSuJKs (Python)