changed math stream

This commit is contained in:
Dominik Krenn 2025-11-05 12:20:59 +01:00
parent 88ee579114
commit 1df893c8f3
2 changed files with 23 additions and 1 deletions

View File

@ -1,6 +1,12 @@
from .engine import clear_logs, add, sub, mul, div, mod, pow, is_even, is_odd from .engine import clear_logs, add, sub, mul, div, mod, pow, is_even, is_odd
from .exceptions import MathStreamError, DivideByZeroError from .exceptions import MathStreamError, DivideByZeroError
from .number import StreamNumber, free_stream, active_streams from .number import (
StreamNumber,
free_stream,
active_streams,
set_manual_free_only,
manual_free_only_enabled,
)
from .utils import collect_garbage, tracked_files from .utils import collect_garbage, tracked_files
__all__ = [ __all__ = [
@ -18,6 +24,8 @@ __all__ = [
"StreamNumber", "StreamNumber",
"free_stream", "free_stream",
"active_streams", "active_streams",
"set_manual_free_only",
"manual_free_only_enabled",
"MathStreamError", "MathStreamError",
"DivideByZeroError", "DivideByZeroError",
] ]

View File

@ -12,6 +12,7 @@ from .utils import (
) )
LOG_DIR = Path("./instance/log") LOG_DIR = Path("./instance/log")
_MANUAL_FREE_ONLY = False
def _ensure_log_dir() -> None: def _ensure_log_dir() -> None:
@ -138,6 +139,8 @@ def _decrement_active(path: Path, delete_file: bool = True) -> None:
def _finalize_instance(path_str: str) -> None: def _finalize_instance(path_str: str) -> None:
if _MANUAL_FREE_ONLY:
return
_decrement_active(Path(path_str)) _decrement_active(Path(path_str))
@ -149,3 +152,14 @@ def free_stream(number: StreamNumber, *, delete_file: bool = True) -> None:
def active_streams() -> Dict[str, int]: def active_streams() -> Dict[str, int]:
"""Return the active StreamNumber paths mapped to in-memory reference counts.""" """Return the active StreamNumber paths mapped to in-memory reference counts."""
return dict(_ACTIVE_COUNTER) return dict(_ACTIVE_COUNTER)
def set_manual_free_only(enabled: bool) -> None:
"""Toggle whether garbage collection happens only via explicit .free() calls."""
global _MANUAL_FREE_ONLY
_MANUAL_FREE_ONLY = bool(enabled)
def manual_free_only_enabled() -> bool:
"""Return the current manual-free-only toggle."""
return _MANUAL_FREE_ONLY