fix: 修复 market.py _put_db 拼写错误和多处连接泄漏
- market.py:308: _put_db(conn) → put_db(_conn) 修复函数名和变量名拼写错误 - market.py: get_fundamental put_db 移到 finally,初始化 conn=None 防 NameError - admin.py: kline_sync_status 和 admin_scan_status put_db 移到 finally
This commit is contained in:
@@ -782,7 +782,6 @@ def kline_sync_status():
|
|||||||
total_stocks = cur.fetchone()[0]
|
total_stocks = cur.fetchone()[0]
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
put_db(conn)
|
|
||||||
|
|
||||||
is_running = _is_kline_sync_running()
|
is_running = _is_kline_sync_running()
|
||||||
|
|
||||||
@@ -858,6 +857,8 @@ def kline_sync_status():
|
|||||||
})
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'success': False, 'error': str(e)}), 500
|
return jsonify({'success': False, 'error': str(e)}), 500
|
||||||
|
finally:
|
||||||
|
put_db(conn)
|
||||||
|
|
||||||
|
|
||||||
# ========== 定时任务监控 ==========
|
# ========== 定时任务监控 ==========
|
||||||
@@ -1301,7 +1302,6 @@ def admin_scan_status():
|
|||||||
triggered = cur.fetchone()[0]
|
triggered = cur.fetchone()[0]
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
put_db(conn)
|
|
||||||
|
|
||||||
is_running = _is_scan_running()
|
is_running = _is_scan_running()
|
||||||
|
|
||||||
@@ -1350,3 +1350,5 @@ def admin_scan_status():
|
|||||||
})
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'success': False, 'error': str(e)}), 500
|
return jsonify({'success': False, 'error': str(e)}), 500
|
||||||
|
finally:
|
||||||
|
put_db(conn)
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ def get_fund_flow_rank():
|
|||||||
return jsonify({'success': True, 'data': flow_data, 'total': len(flow_data),
|
return jsonify({'success': True, 'data': flow_data, 'total': len(flow_data),
|
||||||
'source': 'cache'})
|
'source': 'cache'})
|
||||||
finally:
|
finally:
|
||||||
_put_db(conn)
|
put_db(_conn)
|
||||||
|
|
||||||
return jsonify({'success': True, 'data': [], 'total': 0})
|
return jsonify({'success': True, 'data': [], 'total': 0})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -324,6 +324,7 @@ def get_fundamental(stock_code):
|
|||||||
realtime_data = None
|
realtime_data = None
|
||||||
signal_data = None
|
signal_data = None
|
||||||
|
|
||||||
|
conn = None
|
||||||
try:
|
try:
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
if conn:
|
if conn:
|
||||||
@@ -388,10 +389,10 @@ def get_fundamental(stock_code):
|
|||||||
'indicators': ind,
|
'indicators': ind,
|
||||||
'triggered_count': sig_row[2] or 0,
|
'triggered_count': sig_row[2] or 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
put_db(conn)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"获取数据失败: {e}")
|
print(f"获取数据失败: {e}")
|
||||||
|
finally:
|
||||||
|
put_db(conn)
|
||||||
|
|
||||||
# 优先从数据库获取当日缓存
|
# 优先从数据库获取当日缓存
|
||||||
cached = db_get_fundamental(stock_code)
|
cached = db_get_fundamental(stock_code)
|
||||||
|
|||||||
Reference in New Issue
Block a user