chore: merge nolock.py and gil_enabled.py to gil.py

This commit is contained in:
rus07tam 2025-11-23 11:01:28 +00:00
parent 7b34426c82
commit 498087befb
3 changed files with 16 additions and 21 deletions

View file

@ -3,7 +3,7 @@ from .calls import call, caller
from .exceptions import catch, throw from .exceptions import catch, throw
from .frames import frame from .frames import frame
from .inherit import inherit from .inherit import inherit
from .nolock import nolock from .gil import GIL_ENABLED, nolock
from .side import side, side_func from .side import side, side_func
from .this import this from .this import this
from .to_async import to_async from .to_async import to_async
@ -13,6 +13,7 @@ __all__ = [
"caller", "caller",
"get_or_set_attr", "get_or_set_attr",
"get_attrs", "get_attrs",
"GIL_ENABLED",
"frame", "frame",
"inherit", "inherit",
"nolock", "nolock",

View file

@ -4,6 +4,9 @@ if TYPE_CHECKING:
GIL_ENABLED: Final[bool] = bool(...) GIL_ENABLED: Final[bool] = bool(...)
""" """
Whether the GIL is enabled.""" Whether the GIL is enabled."""
def nolock() -> None: ...
else: else:
import sys import sys
@ -12,3 +15,14 @@ else:
GIL_ENABLED = sys._is_gil_enabled() GIL_ENABLED = sys._is_gil_enabled()
else: else:
GIL_ENABLED = True GIL_ENABLED = True
if GIL_ENABLED:
import time
def nolock() -> None:
time.sleep(0.001)
else:
def nolock() -> None:
pass

View file

@ -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