TimeOut.jl
After a long discussion thread, I thought I should bring this question to a larger audience, to hear what other people think. I have setup a draft package TimeOut.jl
to fill the need for a timeout function and macro.
I’ve seen various implementations, e.g. in HTTP/ConcurrentUtilities, but none of them did explicitly export their solution as a function, although I think the need for such functionality is there.
The final code, I ended up with, is longer than I previously expected, that’s one more reason to setup this package.
The main exports are timeout()
and@timeout
. These versions of timeout()
and @timeout
will not block when tasks cannot be stopped, at least if multiple threads are available.
There’s also killtask()
which is meant to replace the many @async Base.throwto(task, InterruptException())
that are still found in the wild… This version hopefully never throws and should be safe against race conditions.
Future
This package is not registered and maybe in this form will never be registered. The code could as well go into a different more visible package, e.g. ThreadPools. Alternatively it could live on its own and enhance methods from ThreadPools with a timeout parameter via extensions. In any case, I shouldn’t be the (only) maintainer.
It is also well possible that I am not aware of an already existing solution or approach, in that case I’m also happy to learn about that.