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 and silent crash #7626

Closed
bdeonovic opened this issue Jul 16, 2014 · 3 comments
Closed

@async and silent crash #7626

bdeonovic opened this issue Jul 16, 2014 · 3 comments

Comments

@bdeonovic
Copy link
Contributor

If an @async block encounters an error it silently stops running. Any way to at least print out some errors?

@JeffBezanson
Copy link
Member

To find out that a Task exited with an error, somebody has to look. You can inspect t.exception, or wait, which will propagate the exception:

julia> t = @async error("hello")
Task (failed) @0x0000000003a74870

julia> wait(t)
ERROR: hello
 in wait at ./task.jl:53

julia> t.exception
ErrorException("hello")

The operations "see if task failed" and "print error message" are separated, so you can do one without the other.

@fonsp
Copy link
Member

fonsp commented Jan 7, 2021

For anyone struggling with this problem, here's a version of @async that prints errors to the terminal immediately:

"Like @async except it prints errors to the terminal. 👶"
macro asynclog(expr)
    quote
        @async try
            $(esc(expr))
        catch ex
            bt = stacktrace(catch_backtrace())
            showerror(stderr, ex, bt)
            rethrow(ex)
        end
    end
end

@notinaboat
Copy link
Contributor

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

4 participants