From 29954592f49052159af2cce536f0f4e11efe540b Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 15 Jul 2024 11:55:34 -0400 Subject: [PATCH] add note about Downloader when multithreading --- README.md | 10 +++++++--- src/Downloads.jl | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b1cbb3b..5945c37 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,9 @@ If the `downloader` keyword argument is provided, it must be a `Downloader` object. Resources and connections will be shared between downloads performed by the same `Downloader` and cleaned up automatically when the object is garbage collected or there have been no downloads performed with it for a grace period. -See `Downloader` for more info about configuration and usage. +Note that when multithreading it may be beneficial to use task-local `Downloader` +objects when running concurrent tasks. See `Downloader` for more info about configuration +and usage. If the `headers` keyword argument is provided, it must be a vector or dictionary whose elements are all pairs of strings. These pairs are passed as headers when @@ -134,11 +136,11 @@ with getting a response at all, then a `RequestError` is thrown or returned. ```jl default_downloader!( downloader = - ) + ) ``` - `downloader :: Downloader` -Set the default `Downloader`. If no argument is provided, resets the default downloader +Set the default `Downloader`. If no argument is provided, resets the default downloader so that a fresh one is created the next time the default downloader is needed. ### Response @@ -207,6 +209,8 @@ garbage collected, whichever comes first. If the grace period is set to zero, all resources will be cleaned up immediately as soon as there are no more ongoing downloads in progress. If the grace period is set to `Inf` then resources are not cleaned up until `Downloader` is garbage collected. +Note that when multithreading it may be beneficial to use task-local `Downloader` +objects when running concurrent tasks. ## Mutual TLS using Downloads diff --git a/src/Downloads.jl b/src/Downloads.jl index 5a3c214..8b96069 100644 --- a/src/Downloads.jl +++ b/src/Downloads.jl @@ -35,6 +35,8 @@ garbage collected, whichever comes first. If the grace period is set to zero, all resources will be cleaned up immediately as soon as there are no more ongoing downloads in progress. If the grace period is set to `Inf` then resources are not cleaned up until `Downloader` is garbage collected. +Note that when multithreading it may be beneficial to use task-local `Downloader` +objects when running concurrent tasks. """ mutable struct Downloader multi::Multi @@ -200,7 +202,9 @@ If the `downloader` keyword argument is provided, it must be a `Downloader` object. Resources and connections will be shared between downloads performed by the same `Downloader` and cleaned up automatically when the object is garbage collected or there have been no downloads performed with it for a grace period. -See `Downloader` for more info about configuration and usage. +Note that when multithreading it may be beneficial to use task-local `Downloader` +objects when running concurrent tasks. See `Downloader` for more info about +configuration and usage. If the `headers` keyword argument is provided, it must be a vector or dictionary whose elements are all pairs of strings. These pairs are passed as headers when