-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Uncaught exceptions from tasks #32034
Comments
Thanks for the pointers! Is there a way to have those exceptions (within tasks that were spawned by the current package's code) be caught automatically in package tests? If not, I think any unobserved task should be considered a code smell. Every |
It's very hard to have an automatic fallback for otherwise-uncaught exceptions in tasks, since in general it requires looking into the future: if somebody is going to call |
We could add something like |
That sounds like a good idea. Having a way to make that the default (for The parser should know whether a just created task object is stored somewhere (e.g. ctx = ComputeContext()
@monitor ctx begin
# spawn some tasks
# unrelated/detail: maybe the task constructor should know of the `ctx`
# instead of `@async`: Task(...; ctx=currentcomputecontext())
end
foreach(wait, tasks(ctx)) # or a new `wait(ctx)` Running Such a compute context could also be used for handling cancellation of tasks. Check out golang/go#29011 and the references therein (the above |
Some kind of task context construct is a good idea; that could be discussed in a separate proposal. It's hard to do any sort of global default behavior switch here, because of libraries. You never know what code might be spawning tasks. I would also be against changing this default in Julia 2.0. The problem is not that it's a breaking change, but that it's impossible to know whether an exception in a task will be handled eventually.
Generated functions should absolutely not check environment variables; they need to be pure.
This is a good thought, but this kind of static analysis is very coarse. For example, you might write |
Of those whose return value of the creating code (constructor,
Once the generation is done, they will be pure. What I have in mind is something like @generated foo() = get(ENV, "FOO", "") != "" ? :(42) : :(21) but for macros. Maybe like so (I'm not that proficient writing macros): @generated macro async(f)
if parse(Bool, get(ENV, "JULIA_MONITOR_TASKS", "false"))
:(@monitored_async f)
else
:(@unmonitored_async f)
end
end |
The code generated by a Macros don't need a |
If a task throws an exception it goes down silently. This issue was reported before (#12485) and seemed to be fixed in version 1.1 (#28878), but it popped up (or it didn't) in one of my unit tests. A similar scenario:
broken example
Output:
corrected example
Output:
versioninfo
The text was updated successfully, but these errors were encountered: