@@ -920,7 +920,7 @@ function _precompilepkgs(pkgs::Vector{String},
920
920
try
921
921
# allows processes to wait if another process is precompiling a given package to
922
922
# 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
924
924
Base. with_logger (Base. NullLogger ()) do
925
925
# The false here means we ignore loaded modules, so precompile for a fresh session
926
926
keep_loaded_modules = false
@@ -1101,7 +1101,7 @@ function _color_string(cstr::String, col::Union{Int64, Symbol}, hascolor)
1101
1101
end
1102
1102
1103
1103
# 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 )
1105
1105
pkg, config = pkg_config
1106
1106
flags, cacheflags = config
1107
1107
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
1122
1122
! fancyprint && lock (print_lock) do
1123
1123
println (io, " " , pkg. name, _color_string (" Being precompiled by $(pkgspidlocked[pkg_config]) " , Base. info_color (), hascolor))
1124
1124
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
1134
1140
end
1135
1141
end
1136
1142
return cachefile
0 commit comments