[Ann] TimeOut.jl

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.

10 Likes

This feels like something that should live in Base. Might be worth bringing it up?

Please register the package if no other similar package is brought up. I’ve wanted this functionality several times.

Timeouts have been on my mind a lot, too. I have some stuff in this direction in the public API of ParallelProcessingTools.jl (see src/waiting.jl ), with sleep_ns, idle_sleep, @wait_while, wait_for_any and wait_for_all (the last two still need to be adapted to use the new Julia v1.12 waitany and waitall if no timeout is requested).

These doesn’t really depend on other parts of ParallelProcessingTools, I’d be happy to pull it out and merge it with your code @hhaensel , in some lightweight central package that handles waiting, timeouts and cancellation.

5 Likes

Maybe we could also get a comment from @ararslan or @kristoffer.carlsson whether this a functionality for Base or another official Julia package?