I'm encountering an issue where my program fails to generate a different output with each new post request. Even when I employ a random function in Python, it consistently produces the same output until I manually restart the process.
I expect a different output each time I make a post request without any manual intervention.
This is my main file
import subprocessimport requestsfrom flask import Flask, jsonifyfrom getData.student_data import fetch_student_datafrom getData.room_data import fetch_room_datafrom getData.teacher_data import fetch_teacher_datafrom getData.course_data import fetch_course_datafrom getData.curriculum_data import fetch_curriculum_datafrom scheduler.CSPAlgorithm import CSPAlgorithmclass Scheduler: def __init__(self) -> None: self.getData() def getData(self): self.programs = fetch_student_data() self.courses = fetch_course_data() self.instructors = fetch_teacher_data() self.rooms = fetch_room_data() self.curriculum = fetch_curriculum_data() #print(self.curriculum) def CSP(self): csp = CSPAlgorithm(self.programs, self.courses, self.instructors, self.rooms, self.curriculum) result = csp.define_result() return resultapp = Flask(__name__)class Fetching: def __init__(self): self.url = 'http://192.168.1.1:8080/Schedule/create' def perform_post_request(self, data): response = requests.post(self.url, json=data) if response.status_code in [200, 201]: return response else: print(f"Error in POST request. Status code: {response.status_code}") print(response.text) return response@app.route('/activate_algorithm', methods=['POST'])def activate_csp_algorithm(): try: scheduler = Scheduler() # Create a new instance of the Scheduler class for each request result = scheduler.CSP() fetching_instance = Fetching() for solution in result: response = fetching_instance.perform_post_request(solution) print(response.text) return jsonify({"status": "success", "message": "CSP algorithm activated successfully"}) except Exception as e: return jsonify({"status": "error", "message": str(e)})if __name__ == "__main__": app.run(host="0.0.0.0", port=5000) # scheduler = Scheduler() # p = scheduler.CSP() # print(p)
I use to do this. but still not the solution
import subprocessdef restart_server(): print("Restarting server...") python = sys.executable subprocess.Popen([python, "main.py"]) sys.exit()
@app.route('/restart_server', methods=['POST'])def trigger_restart(): # Perform any necessary cleanup or validation here restart_server() return jsonify({'message': 'Server restarting...'})