From 1061ecc377a053fce0df94e1a19e5260f7c030f5 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 28 Aug 2024 18:07:38 +0100 Subject: [PATCH] Fix setting atexit. Fixes trailing download tasks during precompilation (#257) --- src/Curl/Curl.jl | 18 ++++++++++++++---- src/Curl/Multi.jl | 9 --------- src/Downloads.jl | 1 + 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Curl/Curl.jl b/src/Curl/Curl.jl index cc1b5b1..fd9b4c9 100644 --- a/src/Curl/Curl.jl +++ b/src/Curl/Curl.jl @@ -65,10 +65,6 @@ using Base: OS_HANDLE, preserve_handle, unpreserve_handle include("utils.jl") -function __init__() - @check curl_global_init(CURL_GLOBAL_ALL) -end - const CURL_VERSION_INFO = unsafe_load(curl_version_info(CURLVERSION_NOW)) if CURL_VERSION_INFO.ssl_version == Base.C_NULL const SSL_VERSION = "" @@ -91,6 +87,20 @@ end include("Easy.jl") include("Multi.jl") +function __init__() + @check curl_global_init(CURL_GLOBAL_ALL) + + # Close any Multis and their timers at exit that haven't been finalized by then + Base.atexit() do + while true + w = @lock MULTIS_LOCK (isempty(MULTIS) ? nothing : pop!(MULTIS)) + w === nothing && break + w = w.value + w isa Multi && done!(w) + end + end +end + function with_handle(f, handle::Union{Multi, Easy}) try f(handle) finally diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index c6ed079..33a606b 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -55,15 +55,6 @@ end const MULTIS_LOCK = Base.ReentrantLock() const MULTIS = WeakRef[] -# Close any Multis and their timers at exit that haven't been finalized by then -Base.atexit() do - while true - w = @lock MULTIS_LOCK (isempty(MULTIS) ? nothing : pop!(MULTIS)) - w === nothing && break - w = w.value - w isa Multi && done!(w) - end -end function remove_handle(multi::Multi, easy::Easy) lock(multi.lock) do diff --git a/src/Downloads.jl b/src/Downloads.jl index 5a3c214..ca1710c 100644 --- a/src/Downloads.jl +++ b/src/Downloads.jl @@ -468,6 +468,7 @@ end # Precompile let + Curl.__init__() d = Downloader() f = mktemp()[1] download("file://" * f; downloader=d)