треды поправлены

This commit is contained in:
2025-10-31 18:04:18 +03:00
parent 6ffbcb9de1
commit 735af0e81d

View File

@@ -330,7 +330,14 @@ async def lifespan(app: FastAPI):
GAME_TODAY = is_today GAME_TODAY = is_today
# 4. запускаем "длинные" потоки (они у тебя и так всегда) # 4. запускаем "длинные" потоки (они у тебя и так всегда)
threads_long = [ thread_result_consumer = threading.Thread(
target=results_consumer,
daemon=True,
)
thread_result_consumer.start()
# 5. Подготовим онлайн и офлайн наборы (как у тебя)
threads_live = [
threading.Thread( threading.Thread(
target=get_data_from_API, target=get_data_from_API,
args=( args=(
@@ -367,22 +374,13 @@ async def lifespan(app: FastAPI):
), ),
daemon=True, daemon=True,
), ),
threading.Thread(
target=results_consumer,
daemon=True,
),
]
for t in threads_long:
t.start()
# 5. Подготовим онлайн и офлайн наборы (как у тебя)
threads_live = [
threading.Thread( threading.Thread(
target=get_data_from_API, target=get_data_from_API,
args=( args=(
"game", "game",
URLS["game"].format(host=HOST, game_id=game_id, lang=LANG), URLS["game"].format(host=HOST, game_id=game_id, lang=LANG),
3, 0.00016,
stop_event, stop_event,
), ),
daemon=True, daemon=True,
@@ -487,8 +485,7 @@ async def lifespan(app: FastAPI):
# -------- shutdown -------- # -------- shutdown --------
stop_event.set() stop_event.set()
for t in threads_long: thread_result_consumer.join(timeout=1)
t.join(timeout=1)
# офлайн/онлайн ты можешь не делить тут, но оставлю # офлайн/онлайн ты можешь не делить тут, но оставлю
for t in threads_offline: for t in threads_offline:
t.join(timeout=1) t.join(timeout=1)