Terminator: A Hardcore “Timeout” For Ruby Code

By Peter Cooper

Terminator is a new library developed by Ara Howard and Mikel Lindsaar that solves the problem of Ruby's own "timeout" feature not actually being up to the task of terminating code. timeout is supposed to terminate the execution of a block of code if it's not finished within a certain amount of time, but due to Ruby's threading model it doesn't always work that way!

Initially, Mikel considered SystemTimer - another replacement for timeout. SystemTimer is based upon UNIX alarm signals and, for some reason, still didn't resolve the main problem (although SystemTimer has ridiculously good documentation and is clearly working well for someone). After lamenting on the Ruby-Talk mailing list, Ara Howard stepped in with a potential solution which turned into what is now Terminator.

Terminator works by starting up another Ruby instance that tracks the PID of the Ruby instance that spawned it. Windows is currently not supported.