I have a Julia code where I need to execute two operation in a parallel way. My problem is that I need to stop and kill one operation if it take too much time.
I tried with the Task but now I can't find how to kill a task. My code is:
function mytask(myargs, ch)
# do some work (optimize a problem with Gurobi)
# that can go on for a very long time
put!(ch, computationResult)
end
ch = Channel(1)
task = @async mytask(args, ch)
# now the main task does some other work
# and at the end
if isready(ch)
taskResult = take!(ch)
else
# the result of th async task became useless
# so here I need to kill the async task
end
# continue the execution
I found this similar old question but I think the solution is no longer supported because I can't find the throwto method in the documentation and I also tried it but I get this error message
WARNING: Workqueue inconsistency detected: shift!(Workqueue).state != :queued
ERROR (unhandled task failure): InterruptException:
I'm not forced to use tasks, I can use thread processes or any other solution as long as it works