mirror of
https://github.com/KohakuBlueleaf/KohakuHub.git
synced 2026-03-11 17:34:08 -05:00
non-blocking read + no import in function
This commit is contained in:
@@ -4,6 +4,9 @@ Unified API for accessing run data (scalars, media, tables, histograms).
|
||||
Works in both local and remote modes with project-based organization.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
@@ -71,10 +74,12 @@ async def get_run_status(
|
||||
# Check metadata for creation time
|
||||
metadata_file = run_path / "metadata.json"
|
||||
if metadata_file.exists():
|
||||
import json
|
||||
# Use asyncio.to_thread to avoid blocking
|
||||
def read_metadata():
|
||||
with open(metadata_file, "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
with open(metadata_file, "r") as f:
|
||||
metadata = json.load(f)
|
||||
metadata = await asyncio.to_thread(read_metadata)
|
||||
else:
|
||||
metadata = {}
|
||||
|
||||
@@ -94,8 +99,6 @@ async def get_run_status(
|
||||
# Convert timestamp ms to ISO string
|
||||
ts_ms = latest_step_info.get("timestamp")
|
||||
if ts_ms:
|
||||
from datetime import datetime, timezone
|
||||
|
||||
last_updated = datetime.fromtimestamp(
|
||||
ts_ms / 1000, tz=timezone.utc
|
||||
).isoformat()
|
||||
|
||||
@@ -11,6 +11,7 @@ import time
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
import numpy as np
|
||||
from lance.dataset import LanceDataset
|
||||
from loguru import logger
|
||||
|
||||
@@ -451,8 +452,6 @@ class HybridBoardReader:
|
||||
num_bins = len(counts)
|
||||
|
||||
# Reconstruct bin edges from min/max/num_bins
|
||||
import numpy as np
|
||||
|
||||
bin_edges = np.linspace(min_val, max_val, num_bins + 1).tolist()
|
||||
|
||||
result.append(
|
||||
|
||||
@@ -6,6 +6,8 @@ Combines the best of both worlds:
|
||||
- Adaptive histograms: Lance with percentile-based range tracking
|
||||
"""
|
||||
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
@@ -93,8 +95,6 @@ class HybridStorage:
|
||||
caption: Optional caption
|
||||
"""
|
||||
# Record step info (use current timestamp)
|
||||
from datetime import datetime, timezone
|
||||
|
||||
timestamp_ms = int(datetime.now(timezone.utc).timestamp() * 1000)
|
||||
self.metadata_storage.append_step_info(step, global_step, timestamp_ms)
|
||||
|
||||
@@ -116,8 +116,6 @@ class HybridStorage:
|
||||
table_data: Table dict
|
||||
"""
|
||||
# Record step info
|
||||
from datetime import datetime, timezone
|
||||
|
||||
timestamp_ms = int(datetime.now(timezone.utc).timestamp() * 1000)
|
||||
self.metadata_storage.append_step_info(step, global_step, timestamp_ms)
|
||||
|
||||
@@ -143,8 +141,6 @@ class HybridStorage:
|
||||
precision: "compact" (uint8) or "exact" (int32)
|
||||
"""
|
||||
# Record step info
|
||||
from datetime import datetime, timezone
|
||||
|
||||
timestamp_ms = int(datetime.now(timezone.utc).timestamp() * 1000)
|
||||
self.metadata_storage.append_step_info(step, global_step, timestamp_ms)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user