Skip to content

Commit 44a1257

Browse files
committed
Refactor sys checks in get_backend and _get_mp_context
1 parent c4d381f commit 44a1257

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/freethreading/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_backend() -> Literal["threading", "multiprocessing"]:
8888
Literal['threading', 'multiprocessing']
8989
'threading' when GIL is disabled, and 'multiprocessing' otherwise.
9090
"""
91-
if sys._is_gil_enabled() if hasattr(sys, "_is_gil_enabled") else True:
91+
if getattr(sys, "_is_gil_enabled", lambda: True)():
9292
return "multiprocessing"
9393
return "threading"
9494

@@ -108,7 +108,7 @@ def _get_mp_context():
108108
raise AssertionError(
109109
"Attempting to get multiprocessing context while on threading backend"
110110
)
111-
if sys.platform == "win32" or sys.platform == "darwin":
111+
if sys.platform in ("win32", "darwin"):
112112
return get_context("spawn")
113113
return get_context("forkserver")
114114

0 commit comments

Comments
 (0)