Skip to content

Commit 4564bc4

Browse files
Try using weakref?
1 parent 348f2b6 commit 4564bc4

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

Tools/jit/_llvm.py

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

1112
_LLVM_VERSION = 19
1213
_LLVM_VERSION_PATTERN = re.compile(rf"version\s+{_LLVM_VERSION}\.\d+\.\d+\S*\s+")
@@ -32,14 +33,16 @@ async def wrapper(
3233
return wrapper
3334

3435

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

3740

3841
def _get_cores() -> asyncio.BoundedSemaphore:
39-
global _CORES
40-
if _CORES is None:
41-
_CORES = asyncio.BoundedSemaphore(os.cpu_count() or 1)
42-
return _CORES
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]
4346

4447

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

Tools/jit/build.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
args = parser.parse_args()
2929

3030
if len(args.target) == 1:
31-
args.target.debug = args.debug
32-
args.target.verbose = args.verbose
33-
args.target.build(pathlib.Path.cwd(), comment=comment, force=args.force)
31+
target = args.target[0]
32+
target.debug = args.debug
33+
target.verbose = args.verbose
34+
target.build(pathlib.Path.cwd(), comment=comment, force=args.force)
3435

3536
else:
3637
# Build for multiple targets (e.g. universal2)

configure

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,50 +2617,50 @@ AS_VAR_IF([ac_cv_gcc_compat], [yes], [
26172617
UNIVERSAL_ARCH_FLAGS="-arch ppc -arch i386"
26182618
LIPO_32BIT_FLAGS=""
26192619
ARCH_RUN_32BIT=""
2620-
ARCH_TRIPLES=`echo {ppc,i386}-apple-darwin`
2620+
ARCH_TRIPLES=`echo {ppc,i386}-apple-darwin`
26212621
;;
26222622
64-bit)
26232623
UNIVERSAL_ARCH_FLAGS="-arch ppc64 -arch x86_64"
26242624
LIPO_32BIT_FLAGS=""
26252625
ARCH_RUN_32BIT="true"
2626-
ARCH_TRIPLES=`echo {ppc64,x86_64}-apple-darwin`
2626+
ARCH_TRIPLES=`echo {ppc64,x86_64}-apple-darwin`
26272627
;;
26282628
all)
26292629
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch ppc -arch ppc64 -arch x86_64"
26302630
LIPO_32BIT_FLAGS="-extract ppc7400 -extract i386"
26312631
ARCH_RUN_32BIT="/usr/bin/arch -i386 -ppc"
2632-
ARCH_TRIPLES=`echo {i386,ppc,ppc64,x86_64}-apple-darwin`
2632+
ARCH_TRIPLES=`echo {i386,ppc,ppc64,x86_64}-apple-darwin`
26332633
;;
26342634
universal2)
26352635
UNIVERSAL_ARCH_FLAGS="-arch arm64 -arch x86_64"
26362636
LIPO_32BIT_FLAGS=""
26372637
LIPO_INTEL64_FLAGS="-extract x86_64"
26382638
ARCH_RUN_32BIT="true"
2639-
ARCH_TRIPLES=`echo {aarch64,x86_64}-apple-darwin`
2639+
ARCH_TRIPLES=`echo {aarch64,x86_64}-apple-darwin`
26402640
;;
26412641
intel)
26422642
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch x86_64"
26432643
LIPO_32BIT_FLAGS="-extract i386"
26442644
ARCH_RUN_32BIT="/usr/bin/arch -i386"
2645-
ARCH_TRIPLES=`echo {i386,x86_64}-apple-darwin`
2645+
ARCH_TRIPLES=`echo {i386,x86_64}-apple-darwin`
26462646
;;
26472647
intel-32)
26482648
UNIVERSAL_ARCH_FLAGS="-arch i386"
26492649
LIPO_32BIT_FLAGS=""
26502650
ARCH_RUN_32BIT=""
2651-
ARCH_TRIPLES=i386-apple-darwin
2651+
ARCH_TRIPLES=i386-apple-darwin
26522652
;;
26532653
intel-64)
26542654
UNIVERSAL_ARCH_FLAGS="-arch x86_64"
26552655
LIPO_32BIT_FLAGS=""
26562656
ARCH_RUN_32BIT="true"
2657-
ARCH_TRIPLES=x86_64-apple-darwin
2657+
ARCH_TRIPLES=x86_64-apple-darwin
26582658
;;
26592659
3-way)
26602660
UNIVERSAL_ARCH_FLAGS="-arch i386 -arch ppc -arch x86_64"
26612661
LIPO_32BIT_FLAGS="-extract ppc7400 -extract i386"
26622662
ARCH_RUN_32BIT="/usr/bin/arch -i386 -ppc"
2663-
ARCH_TRIPLES=`echo {i386,ppc,x86_64}-apple-darwin`
2663+
ARCH_TRIPLES=`echo {i386,ppc,x86_64}-apple-darwin`
26642664
;;
26652665
*)
26662666
AC_MSG_ERROR([proper usage is --with-universal-arch=universal2|32-bit|64-bit|all|intel|3-way])
@@ -2776,7 +2776,7 @@ AS_VAR_IF([jit_flags],
27762776
[],
27772777
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
27782778
AS_VAR_SET([REGEN_JIT_COMMAND],
2779-
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-host}"])
2779+
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host}"])
27802780
AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
27812781
AS_VAR_IF([Py_DEBUG],
27822782
[true],

0 commit comments

Comments
 (0)