@@ -920,7 +920,7 @@ function _precompilepkgs(pkgs::Vector{String},
920920 try
921921 # allows processes to wait if another process is precompiling a given package to
922922 # a functionally identical package cache (except for preferences, which may differ)
923- t = @elapsed ret = precompile_pkgs_maybe_cachefile_lock (io, print_lock, fancyprint, pkg_config, pkgspidlocked, hascolor) do
923+ t = @elapsed ret = precompile_pkgs_maybe_cachefile_lock (io, print_lock, fancyprint, pkg_config, pkgspidlocked, hascolor, parallel_limiter ) do
924924 Base. with_logger (Base. NullLogger ()) do
925925 # The false here means we ignore loaded modules, so precompile for a fresh session
926926 keep_loaded_modules = false
@@ -1101,7 +1101,7 @@ function _color_string(cstr::String, col::Union{Int64, Symbol}, hascolor)
11011101end
11021102
11031103# Can be merged with `maybe_cachefile_lock` in loading?
1104- function precompile_pkgs_maybe_cachefile_lock (f, io:: IO , print_lock:: ReentrantLock , fancyprint:: Bool , pkg_config, pkgspidlocked, hascolor)
1104+ function precompile_pkgs_maybe_cachefile_lock (f, io:: IO , print_lock:: ReentrantLock , fancyprint:: Bool , pkg_config, pkgspidlocked, hascolor, parallel_limiter :: Base.Semaphore )
11051105 pkg, config = pkg_config
11061106 flags, cacheflags = config
11071107 FileWatching = Base. loaded_modules[Base. PkgId (Base. UUID (" 7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" ), " FileWatching" )]
@@ -1122,15 +1122,21 @@ function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLo
11221122 ! fancyprint && lock (print_lock) do
11231123 println (io, " " , pkg. name, _color_string (" Being precompiled by $(pkgspidlocked[pkg_config]) " , Base. info_color (), hascolor))
11241124 end
1125- # wait until the lock is available
1126- FileWatching. mkpidlock (pidfile; stale_age) do
1127- # double-check in case the other process crashed or the lock expired
1128- if Base. isprecompiled (pkg; ignore_loaded= true , flags= cacheflags) # don't use caches for this as the env state will have changed
1129- return nothing # returning nothing indicates a process waited for another
1130- else
1131- delete! (pkgspidlocked, pkg_config)
1132- return f () # precompile
1133- end
1125+ Base. release (parallel_limiter) # release so other work can be done while waiting
1126+ try
1127+ # wait until the lock is available
1128+ @invokelatest Base. mkpidlock_hook (() -> begin
1129+ # double-check in case the other process crashed or the lock expired
1130+ if Base. isprecompiled (pkg; ignore_loaded= true , flags= cacheflags) # don't use caches for this as the env state will have changed
1131+ return nothing # returning nothing indicates a process waited for another
1132+ else
1133+ delete! (pkgspidlocked, pkg_config)
1134+ Base. acquire (f, parallel_limiter) # precompile
1135+ end
1136+ end ,
1137+ pidfile; stale_age)
1138+ finally
1139+ Base. acquire (parallel_limiter) # re-acquire so the outer release is balanced
11341140 end
11351141 end
11361142 return cachefile
0 commit comments