Skip to content

Add create_files #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.4.3"
ClusterManagers = "34f1f09b-3a8b-5176-ab39-66d58a4d544e"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
ThreadPinning = "811555cd-349b-4f26-b7bc-1f208b848042"
Expand All @@ -14,6 +15,7 @@ ThreadPinning = "811555cd-349b-4f26-b7bc-1f208b848042"
ClusterManagers = "0.4.6"
Distributed = "1"
LinearAlgebra = "1"
Logging = "1"
Parameters = "0.12, 0.13"
Pkg = "1"
ThreadPinning = "0.7.22"
Expand Down
4 changes: 4 additions & 0 deletions src/ParallelProcessingTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ import Pkg
import ClusterManagers
import ThreadPinning

using Logging: @logmsg, LogLevel, Info, Debug

using Parameters: @with_kw

include("exceptions.jl")
include("fileio.jl")
include("threadsafe.jl")
include("threadlocal.jl")
include("onthreads.jl")
Expand Down
50 changes: 50 additions & 0 deletions src/exceptions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file is a part of ParallelProcessingTools.jl, licensed under the MIT License (MIT).

"""
ParallelProcessingTools.original_exception(err)

Replaces `TaskFailedException`s and `RemoteException`s with the underlying
exception that originated within the task or on the remote process.
"""
function original_exception end

original_exception(err) = err
original_exception(err::CompositeException) = CompositeException(original_exception.(err.exceptions))
original_exception(err::TaskFailedException) = err.task.result
original_exception(err::RemoteException) = err.captured.ex


"""
ParallelProcessingTools.onlyfirst_exception(err)

Replaces `CompositeException`s with their first exception.

Also employs `original_exception` if `simplify` is `true`.
"""
function onlyfirst_exception end

onlyfirst_exception(err) = err
onlyfirst_exception(err::CompositeException) = first(err.exceptions)


"""
@userfriendly_exceptions expr

Transforms exceptions originating from `expr` into more user-friendly ones.

If multiple exceptions originate from parallel code in `expr`, only one
is rethrown, and `TaskFailedException`s and `RemoteException`s are replaced
by the original exceptions that caused them.

See [`original_exception`] and [`onlyfirst_exception`](@ref).
"""
macro userfriendly_exceptions(expr)
quote
try
$(esc(expr))
catch err
rethrow(original_exception(onlyfirst_exception(err)))
end
end
end
export @userfriendly_exceptions
Loading