clear some variables when they are not needed anymore

This commit is contained in:
LeonOstrez
2025-07-08 21:40:22 +02:00
parent 27ddc4a9cb
commit 2f51ffc88c
2 changed files with 10 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import asyncio
import atexit
import gc
import signal
import sys
import traceback
@@ -273,6 +274,9 @@ async def run_pythagora_session(sm: StateManager, ui: UIBase, args: Namespace):
convo = await load_convo(sm, project_states=fe_states)
await print_convo(ui=ui, convo=convo, fake=False)
# Clear fe_states from memory after conversation is loaded
del fe_states
gc.collect() # Force garbage collection to free memory immediately
if last_task_in_db:
# if there is a task in the db (we are at backend stage), print backend convo history and add task back logs and front logs headers
await ui.send_front_logs_headers(
@@ -297,6 +301,10 @@ async def run_pythagora_session(sm: StateManager, ui: UIBase, args: Namespace):
convo = await load_convo(sm, project_states=be_states)
await print_convo(ui=ui, convo=convo, fake=False)
# Clear be_states from memory after conversation is loaded
del be_states
gc.collect() # Force garbage collection to free memory immediately
else:
sm.fe_auto_debug = True
success = await start_new_project(sm, ui, args)

View File

@@ -665,13 +665,14 @@ class IPCServer:
:param message: Request message.
:param writer: Stream writer to send response.
"""
log.debug("Got _handle_task_convo request with message: %s", message)
log.debug("Got _handle_task_convo request")
try:
task_id = message.content.get("task_id", "")
if task_id:
task_id = uuid.UUID(task_id)
start_project_id = uuid.UUID(message.content.get("start_id", ""))
end_project_id = uuid.UUID(message.content.get("end_id", ""))
log.debug(f"task_id: {task_id}, start_project_id: {start_project_id}, end_project_id: {end_project_id}")
if start_project_id and end_project_id:
project_states = await self.state_manager.get_project_states_in_between(