diff --git a/src/snakia/utils/__init__.py b/src/snakia/utils/__init__.py index cc6694a..6b73ce8 100644 --- a/src/snakia/utils/__init__.py +++ b/src/snakia/utils/__init__.py @@ -3,7 +3,7 @@ from .calls import call, caller from .exceptions import catch, throw from .frames import frame from .inherit import inherit -from .nolock import nolock +from .gil import GIL_ENABLED, nolock from .side import side, side_func from .this import this from .to_async import to_async @@ -13,6 +13,7 @@ __all__ = [ "caller", "get_or_set_attr", "get_attrs", + "GIL_ENABLED", "frame", "inherit", "nolock", diff --git a/src/snakia/utils/gil_enabled.py b/src/snakia/utils/gil.py similarity index 63% rename from src/snakia/utils/gil_enabled.py rename to src/snakia/utils/gil.py index 3ba393b..7cf6719 100644 --- a/src/snakia/utils/gil_enabled.py +++ b/src/snakia/utils/gil.py @@ -4,6 +4,9 @@ if TYPE_CHECKING: GIL_ENABLED: Final[bool] = bool(...) """ Whether the GIL is enabled.""" + + def nolock() -> None: ... + else: import sys @@ -12,3 +15,14 @@ else: GIL_ENABLED = sys._is_gil_enabled() else: GIL_ENABLED = True + + if GIL_ENABLED: + import time + + def nolock() -> None: + time.sleep(0.001) + + else: + + def nolock() -> None: + pass diff --git a/src/snakia/utils/nolock.py b/src/snakia/utils/nolock.py deleted file mode 100644 index 39f001c..0000000 --- a/src/snakia/utils/nolock.py +++ /dev/null @@ -1,20 +0,0 @@ -from typing import TYPE_CHECKING - -from .gil_enabled import GIL_ENABLED - -if TYPE_CHECKING: - - def nolock() -> None: ... - -else: - - if GIL_ENABLED: - import time - - def nolock() -> None: - time.sleep(0.001) - - else: - - def nolock() -> None: - pass