From c5df676af67b2159f3f281d5d07504ad10ca5496 Mon Sep 17 00:00:00 2001 From: freedakgmail Date: Wed, 22 Jul 2026 07:35:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20market.py=20=5Fput?= =?UTF-8?q?=5Fdb=20=E6=8B=BC=E5=86=99=E9=94=99=E8=AF=AF=E5=92=8C=E5=A4=9A?= =?UTF-8?q?=E5=A4=84=E8=BF=9E=E6=8E=A5=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- stock-html/routes/admin.py | 6 ++++-- stock-html/routes/market.py | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stock-html/routes/admin.py b/stock-html/routes/admin.py index 2e84ff3..9545cb5 100644 --- a/stock-html/routes/admin.py +++ b/stock-html/routes/admin.py @@ -782,7 +782,6 @@ def kline_sync_status(): total_stocks = cur.fetchone()[0] cur.close() - put_db(conn) is_running = _is_kline_sync_running() @@ -858,6 +857,8 @@ def kline_sync_status(): }) except Exception as e: return jsonify({'success': False, 'error': str(e)}), 500 + finally: + put_db(conn) # ========== 定时任务监控 ========== @@ -1301,7 +1302,6 @@ def admin_scan_status(): triggered = cur.fetchone()[0] cur.close() - put_db(conn) is_running = _is_scan_running() @@ -1350,3 +1350,5 @@ def admin_scan_status(): }) except Exception as e: return jsonify({'success': False, 'error': str(e)}), 500 + finally: + put_db(conn) diff --git a/stock-html/routes/market.py b/stock-html/routes/market.py index 4144f29..f96e5a5 100644 --- a/stock-html/routes/market.py +++ b/stock-html/routes/market.py @@ -305,7 +305,7 @@ def get_fund_flow_rank(): return jsonify({'success': True, 'data': flow_data, 'total': len(flow_data), 'source': 'cache'}) finally: - _put_db(conn) + put_db(_conn) return jsonify({'success': True, 'data': [], 'total': 0}) except Exception as e: @@ -324,6 +324,7 @@ def get_fundamental(stock_code): realtime_data = None signal_data = None + conn = None try: conn = get_db() if conn: @@ -388,10 +389,10 @@ def get_fundamental(stock_code): 'indicators': ind, 'triggered_count': sig_row[2] or 0, } - - put_db(conn) except Exception as e: print(f"获取数据失败: {e}") + finally: + put_db(conn) # 优先从数据库获取当日缓存 cached = db_get_fundamental(stock_code)