fix(simulation): guarantee SQLite connection close with finally block
This commit is contained in:
parent
117eabf607
commit
75533e9319
|
|
@ -258,7 +258,7 @@ class IPCHandler:
|
|||
agent_prompts = {} # 记录每个agent的prompt
|
||||
|
||||
for interview in interviews:
|
||||
agent_id = interview.get("agent_id")
|
||||
agent_id = interview.get("agent_id") or 0
|
||||
prompt = interview.get("prompt", "")
|
||||
|
||||
try:
|
||||
|
|
@ -310,6 +310,7 @@ class IPCHandler:
|
|||
if not os.path.exists(db_path):
|
||||
return result
|
||||
|
||||
conn = None
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
|
@ -333,10 +334,11 @@ class IPCHandler:
|
|||
except json.JSONDecodeError:
|
||||
result["response"] = info_json
|
||||
|
||||
conn.close()
|
||||
|
||||
except Exception as e:
|
||||
print(f" 读取Interview结果失败: {e}")
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ class IPCHandler:
|
|||
agent_prompts = {} # 记录每个agent的prompt
|
||||
|
||||
for interview in interviews:
|
||||
agent_id = interview.get("agent_id")
|
||||
agent_id = interview.get("agent_id") or 0
|
||||
prompt = interview.get("prompt", "")
|
||||
|
||||
try:
|
||||
|
|
@ -310,6 +310,7 @@ class IPCHandler:
|
|||
if not os.path.exists(db_path):
|
||||
return result
|
||||
|
||||
conn = None
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
|
@ -333,10 +334,11 @@ class IPCHandler:
|
|||
except json.JSONDecodeError:
|
||||
result["response"] = info_json
|
||||
|
||||
conn.close()
|
||||
|
||||
except Exception as e:
|
||||
print(f" 读取Interview结果失败: {e}")
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue