From 18bd373c1e84109e8a66d03c7e59c3272ddb5e5d Mon Sep 17 00:00:00 2001 From: Benjamin Lorenz Date: Tue, 14 May 2024 12:24:55 +0200 Subject: [PATCH] init: add pidlock for polymake initialization --- Project.toml | 4 +++- src/Polymake.jl | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index f8bd0f3b..fdfaa8e4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Polymake" uuid = "d720cf60-89b5-51f5-aff5-213f193123e7" repo = "https://github.com/oscar-system/Polymake.jl.git" -version = "0.11.16" +version = "0.11.17" [deps] AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" @@ -14,6 +14,7 @@ Mongoc = "4fe8b98c-fc19-5c23-8ec2-168ff83495f2" NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908" Ninja_jll = "76642167-d241-5cee-8c94-7a494e8cb7b7" Perl_jll = "83958c19-0796-5285-893e-a1267f8ec499" +Pidfile = "fa939f87-e72e-5be4-a000-7fc836dbe307" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" Scratch = "6c6a2e73-6563-6170-7368-637461726353" @@ -35,6 +36,7 @@ Mongoc = "~0.6.0, ~0.7.0, ~0.8.0, ~0.9.0" NetworkOptions = "1.2" Ninja_jll = "^1.11.1" Perl_jll = "^5.34.0" +Pidfile = "^1.3" Pkg = "^1.6" REPL = "^1.6" Scratch = "^1.1" diff --git a/src/Polymake.jl b/src/Polymake.jl index afbf2da2..b6d521ce 100644 --- a/src/Polymake.jl +++ b/src/Polymake.jl @@ -32,6 +32,7 @@ using CxxWrap using BinaryWrappers using Scratch +import Pidfile import Perl_jll import Ninja_jll @@ -188,6 +189,7 @@ function __init__() Downloads.default_downloader!(Downloads.Downloader(grace=0.01)) end # we run this on every init to make sure all artifacts still exist + # (this code should be race condition free even with multiple processes) prepare_deps_tree(polymake_deps_tree) @static if isdefined(Downloads, :default_downloader!) # restore default @@ -243,8 +245,11 @@ function __init__() try show_banner = should_show_banner() && !any(x->x.name in ["Oscar"], keys(Base.package_locks)) - - initialize_polymake_with_dir("$(polymake_extension_config);user=$(polymake_user_dir)", installtop, installarch, show_banner) + mkpath(polymake_user_dir) + # lock to avoid race-conditions when recompiling wrappers in multiple processes + Pidfile.mkpidlock("$(polymake_user_dir)/userdir.lock") do + initialize_polymake_with_dir("$(polymake_extension_config);user=$(polymake_user_dir)", installtop, installarch, show_banner) + end if !show_banner shell_execute(raw"$Verbose::credits=\"0\";") end