# portfolio/app.py from flask import Flask, render_template, url_for, redirect # from npc_social_network.routes.npc_route import npc_bp # from npc_social_network import simulation_core # from stock.routes.stock_route import stock_bp import threading # ------------------------------------------------------------------- # 파일 1: portfolio/app.py (수정) # 역할: 전체 포트폴리오의 진입점. # NPC 시뮬레이션 스레드를 시작하고, 관련 URL 그룹(Blueprint)을 등록합니다. # ------------------------------------------------------------------- # 시뮬레이션이 여러 번 초기화되는 것을 방지하기 위한 잠금 장치 init_lock = threading.Lock() simulation_initialized = False def create_app(): """Flask 앱을 생성하고, 필요한 Blueprint를 등록하는 팩토리 함수.""" app = Flask(__name__, template_folder='templates') # static/template 경로를 기본값 try: from npc_social_network.routes.npc_route import npc_bp app.register_blueprint(npc_bp) print("✅ 'npc_social' Blueprint가 성공적으로 등록되었습니다.") # app.register_blueprint(stock_bp) except Exception as e: import traceback print("="*60) print("❌ CRITICAL ERROR: Blueprint 등록 중 에러가 발생했습니다!") print(f" 에러 메시지: {e}") print("="*60) traceback.print_exc() # 에러의 전체 경로를 출력합니다. print("="*60) # 이 에러가 해결될 때까지 서버는 정상 작동하지 않을 수 있습니다. # --- FINAL DEBUGGING TOOL END --- # 포트폴리오의 메인 랜딩 페이지 @app.route("/") def index(): return render_template("main.html") return app if __name__ == '__main__': # 1. flask 앱 실행 app = create_app() # 2. NPC 시뮬레이션 초기화 및 백그라운드 스레드 시작 try: from npc_social_network import simulation_core simulation_core.initialize_simulation() print("✅ 시뮬레이션이 성공적으로 초기화되었습니다.") except Exception as e: import traceback print("="*60) print("❌ CRITICAL ERROR: 시뮬레이션 초기화 중 에러가 발생했습니다!") print(f" 에러 메시지: {e}") print("="*60) traceback.print_exc() print("="*60) # 3. Flask 웹 서버 실행 # use_reloader=False는 디버그 모드에서 앱이 두 번 실행되는 것을 방지하여, # 시뮬레이션 스레드가 두 번 시작되지 않도록 합니다. app.run(debug=True, use_reloader=False, port=5000)