From 81012e57be84eb0fad24ec37980c7df41d979d1e Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 28 Aug 2024 17:45:11 +0100 Subject: [PATCH] fix setting atexit --- 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)