mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 14:24:15 +08:00
- 市场环境: 新增情绪周期6阶段(冰点/启动/主升/高潮/退潮/修复, 连板梯队驱动, EMA平滑+2日确认+弱档否决, 平均段长9.7天)与概念/行业主线排名(涨停梯队聚合, 可配置宽基/风格标签过滤); 市场环境页重构, regime 透明加列, 与5档state并存 - 挖掘: 因子与策略挖掘全链路(API/worker/进程锁/候选库/前端工作台/文档), 周度调度默认关闭且永不自动发布 - 回测: 财务快照因子(点时口径), 批量回测预计算共享下期收益, 信号路径矩阵列依赖展开修复(consecutive_limit_ups 缺列报错) - 数据/性能: enriched 生成与预热治理, 重任务限流, 行情/K线缓存复用, 时区修复 - 测试: 后端全量 914 通过; GUI 黑盒验证截图存证 gui-test-screenshots/
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import threading
|
|
from collections.abc import Callable
|
|
|
|
|
|
class MatrixCachePrewarmOwner:
|
|
def __init__(self) -> None:
|
|
self._lock = threading.Lock()
|
|
self._cancel_event = threading.Event()
|
|
self._thread: threading.Thread | None = None
|
|
|
|
@property
|
|
def cancel_event(self) -> threading.Event:
|
|
return self._cancel_event
|
|
|
|
def schedule(self, target: Callable[[], None]) -> bool:
|
|
with self._lock:
|
|
if self._cancel_event.is_set():
|
|
return False
|
|
if self._thread is not None and self._thread.is_alive():
|
|
return False
|
|
thread = threading.Thread(
|
|
target=self._run,
|
|
args=(target,),
|
|
name="matrix-cache-prewarm",
|
|
daemon=True,
|
|
)
|
|
self._thread = thread
|
|
thread.start()
|
|
return True
|
|
|
|
def shutdown(self, timeout: float = 5.0) -> bool:
|
|
self._cancel_event.set()
|
|
with self._lock:
|
|
thread = self._thread
|
|
if thread is None:
|
|
return True
|
|
thread.join(timeout=max(0.0, timeout))
|
|
return not thread.is_alive()
|
|
|
|
def _run(self, target: Callable[[], None]) -> None:
|
|
try:
|
|
target()
|
|
finally:
|
|
with self._lock:
|
|
if self._thread is threading.current_thread():
|
|
self._thread = None
|