changed math stream
This commit is contained in:
parent
88ee579114
commit
1df893c8f3
@ -1,6 +1,12 @@
|
||||
from .engine import clear_logs, add, sub, mul, div, mod, pow, is_even, is_odd
|
||||
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
|
||||
|
||||
__all__ = [
|
||||
@ -18,6 +24,8 @@ __all__ = [
|
||||
"StreamNumber",
|
||||
"free_stream",
|
||||
"active_streams",
|
||||
"set_manual_free_only",
|
||||
"manual_free_only_enabled",
|
||||
"MathStreamError",
|
||||
"DivideByZeroError",
|
||||
]
|
||||
|
||||
@ -12,6 +12,7 @@ from .utils import (
|
||||
)
|
||||
|
||||
LOG_DIR = Path("./instance/log")
|
||||
_MANUAL_FREE_ONLY = False
|
||||
|
||||
|
||||
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:
|
||||
if _MANUAL_FREE_ONLY:
|
||||
return
|
||||
_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]:
|
||||
"""Return the active StreamNumber paths mapped to in-memory reference counts."""
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user