Skip to content
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

@async error() isn't being printed #36854

Closed
robsmith11 opened this issue Jul 30, 2020 · 5 comments
Closed

@async error() isn't being printed #36854

robsmith11 opened this issue Jul 30, 2020 · 5 comments

Comments

@robsmith11
Copy link
Contributor

robsmith11 commented Jul 30, 2020

From searching, I thought there were fixes for this, but I'm still seeing no printed error on a current nightly:

julia> versioninfo()
Julia Version 1.6.0-DEV.551
Commit 470dfa6302 (2020-07-29 07:12 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD Ryzen 7 4700U with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, btver1)
Environment:
  JULIA_NUM_THREADS = 8

julia> function f()
        @async error()
        println("done")
       end
f (generic function with 1 method)

julia> f()
done
@StefanKarpinski
Copy link
Member

StefanKarpinski commented Jul 30, 2020

By design. If you don't wait for the result, then it vanishes. Either wait on the result or wrap this in @sync.

julia> function f()
           @sync begin
               @async error()
               println("done")
           end
       end
f (generic function with 1 method)

julia> f()
done
ERROR: TaskFailedException:

See also #33248.

@robsmith11
Copy link
Contributor Author

robsmith11 commented Jul 30, 2020

My actual code has two async threads that are long-running. Is there no way to get an exception from one thread when the other thread never finishes?

Example:

@sync begin
 @async error()
 @async while true
  sleep(1)
 end
end

@JeffBezanson
Copy link
Member

JeffBezanson commented Jul 31, 2020

I recommend wrapping the task in a "monitor" task for debugging:

macro monitored_async(expr)
    quote
        @async begin
            t = @async $(esc(expr))
            try
                wait(t)
            catch
                display(t)
            end
        end
    end
end

@sync begin
    @monitored_async error()
    @async while true
        sleep(1)
    end
end

@JeffBezanson
Copy link
Member

Or, if you want the entire @sync block to propagate an exception as soon as one of the enclosed tasks errors, see Experimental.@sync.

@robsmith11
Copy link
Contributor Author

Thanks! Experimental.@sync is exactly what I want.

Selecting on multiple tasks had also worked:
https://github.com/NHDaly/Select.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants