fix: 修复连接泄漏、double-put_db、北交所映射缺失
- analysis.py: 6个端点将 put_db(conn) 从 try 移到 finally,异常时不泄漏 - trades.py: 移除 update_trade/delete_trade 中多余的 put_db(conn),避免 double-put 破坏连接池 - trades.py: stoploss_check 补充北交所(8/9开头)腾讯API代码映射
This commit is contained in:
@@ -601,9 +601,10 @@ def batch_technical_signals():
|
||||
scan_map[row['code']] = row
|
||||
|
||||
cur.close()
|
||||
put_db(conn)
|
||||
except Exception as e:
|
||||
print(f"批量扫描获取数据失败: {e}")
|
||||
finally:
|
||||
put_db(conn)
|
||||
|
||||
results = []
|
||||
errors = []
|
||||
@@ -919,7 +920,6 @@ def get_scan_results():
|
||||
recommend_counts[disp] = recommend_counts.get(disp, 0) + 1
|
||||
|
||||
cur.close()
|
||||
put_db(conn)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
@@ -939,6 +939,8 @@ def get_scan_results():
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
put_db(conn)
|
||||
|
||||
|
||||
def _compute_recommend(signal_status, indicators, triggered_count, is_holding):
|
||||
@@ -994,7 +996,6 @@ def signal_alerts():
|
||||
WHERE code IN ({placeholders})
|
||||
""", stock_codes)
|
||||
price_rows = cur.fetchall()
|
||||
put_db(conn)
|
||||
|
||||
price_map = {}
|
||||
change_map = {}
|
||||
@@ -1076,6 +1077,8 @@ def signal_alerts():
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
put_db(conn)
|
||||
|
||||
|
||||
def _is_scan_running():
|
||||
@@ -1140,7 +1143,6 @@ def get_scan_status():
|
||||
triggered = cur.fetchone()[0]
|
||||
|
||||
cur.close()
|
||||
put_db(conn)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
@@ -1154,6 +1156,8 @@ def get_scan_status():
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/start_full_scan', methods=['POST'])
|
||||
@@ -1225,7 +1229,6 @@ def get_scan_strategy():
|
||||
""", (scan_date,))
|
||||
rows = cur.fetchall()
|
||||
cur.close()
|
||||
put_db(conn)
|
||||
|
||||
tier1, tier2, tier3, tier4 = [], [], [], []
|
||||
for r in rows:
|
||||
@@ -1306,6 +1309,8 @@ def get_scan_strategy():
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
put_db(conn)
|
||||
|
||||
|
||||
def _get_kline_data(stock_code, days=120):
|
||||
@@ -1357,8 +1362,6 @@ def get_bull_stocks():
|
||||
for p in cur.fetchall():
|
||||
price_map[p['code']] = {'price': float(p['price']), 'change_pct': float(p.get('change_pct') or 0)}
|
||||
|
||||
put_db(conn)
|
||||
|
||||
# ---- 批量计算综合评分 ----
|
||||
scores_map = None
|
||||
try:
|
||||
@@ -1420,6 +1423,8 @@ def get_bull_stocks():
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
put_db(conn)
|
||||
|
||||
|
||||
def _llm_polish_summary(stock_name, stock_code, ai_summary, score, verdict):
|
||||
|
||||
Reference in New Issue
Block a user