Spaces:
Running
Running
Download calculation_lock.py from sisithefox/sisi-astrology-api: direct link, hf CLI and curl.
- Browser
- Download file 779 Bytes
-
https://huggingface.co/spaces/sisithefox/sisi-astrology-api/resolve/main/calculation_lock.py
- Command line
-
hf download hf://spaces/sisithefox/sisi-astrology-api/calculation_lock.py
-
curl -L -o calculation_lock.py https://huggingface.co/spaces/sisithefox/sisi-astrology-api/resolve/main/calculation_lock.py
779 Bytes
| """Serialize calls to process-global Swiss Ephemeris/PyJHora state. | |
| PyJHora changes shared ayanamsa/node settings and patches swisseph functions. | |
| Its temporary stdout replacement is process-global too. FastAPI runs ordinary | |
| def routes in a thread pool, so all chart entry points must use the same lock. | |
| Each server process owns its own library state and lock. | |
| """ | |
| from functools import wraps | |
| from threading import RLock | |
| from typing import Callable, ParamSpec, TypeVar | |
| P = ParamSpec("P") | |
| R = TypeVar("R") | |
| _calculation_lock = RLock() | |
| def serialize_calculation(function: Callable[P, R]) -> Callable[P, R]: | |
| def locked(*args: P.args, **kwargs: P.kwargs) -> R: | |
| with _calculation_lock: | |
| return function(*args, **kwargs) | |
| return locked | |