Skip to content

Commit

Permalink
Fix setting atexit. Fixes trailing download tasks during precompilati…
Browse files Browse the repository at this point in the history
…on (#257)
  • Loading branch information
IanButterworth authored Aug 28, 2024
1 parent b871386 commit 1061ecc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
18 changes: 14 additions & 4 deletions src/Curl/Curl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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
Expand Down
9 changes: 0 additions & 9 deletions src/Curl/Multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Downloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ end

# Precompile
let
Curl.__init__()
d = Downloader()
f = mktemp()[1]
download("file://" * f; downloader=d)
Expand Down

0 comments on commit 1061ecc

Please sign in to comment.