import asyncio, os, json, queue, threading from crawler_service import crawler_thread_worker from dotenv import load_dotenv load_dotenv() async def run_main_test(): user_id = os.getenv("PM_USER_ID") password = os.getenv("PM_PASSWORD") msg_queue = queue.Queue() thread = threading.Thread(target=crawler_thread_worker, args=(msg_queue, user_id, password)) thread.start() print(">>> 메인 워커 실행 중 (필리핀 사무소)...") try: while True: msg_raw = await asyncio.to_thread(msg_queue.get, timeout=300) if msg_raw is None: break msg = json.loads(msg_raw) if msg["type"] == "log": print(f"[LOG] {msg['message']}") elif msg["type"] == "done": print(f"\n[DONE] 최종 결과: {msg['data']}") break except queue.Empty: print(">>> 타임아웃") finally: thread.join() if __name__ == "__main__": asyncio.run(run_main_test())