Skip to content

Commit 49f86a1

Browse files
Remove weakref and lazily instantiate cores
1 parent 2d381ca commit 49f86a1

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Tools/jit/_llvm.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import shlex
88
import subprocess
99
import typing
10-
import weakref
1110

1211
_LLVM_VERSION = 19
1312
_LLVM_VERSION_PATTERN = re.compile(rf"version\s+{_LLVM_VERSION}\.\d+\.\d+\S*\s+")
@@ -33,16 +32,14 @@ async def wrapper(
3332
return wrapper
3433

3534

36-
_CORES_BY_LOOP: weakref.WeakKeyDictionary[
37-
asyncio.AbstractEventLoop, asyncio.BoundedSemaphore
38-
] = weakref.WeakKeyDictionary()
35+
_CORES: asyncio.BoundedSemaphore | None = None
3936

4037

4138
def _get_cores() -> asyncio.BoundedSemaphore:
42-
loop = asyncio.get_running_loop()
43-
if loop not in _CORES_BY_LOOP:
44-
_CORES_BY_LOOP[loop] = asyncio.BoundedSemaphore(os.cpu_count())
45-
return _CORES_BY_LOOP[loop]
39+
global _CORES
40+
if _CORES is None:
41+
_CORES = asyncio.BoundedSemaphore(os.cpu_count() or 1)
42+
return _CORES
4643

4744

4845
async def _run(tool: str, args: typing.Iterable[str], echo: bool = False) -> str | None:

0 commit comments

Comments
 (0)