subexec
subexec copied to clipboard
Examples in README fail
Looks like subexec's timeout functionality doesn't work unless you specify a logfile.
In https://github.com/nulayer/subexec/blob/master/lib/subexec.rb#L80, #readlines blocks.
$ time ruby -r subexec -e 'Subexec.run "echo 'hello' && sleep 3", :timeout => 1'
0.30s user 0.06s system 10% cpu 3.369 total
IO#readlines
blocks until #close
is called on all the handles to the write side of the pipe, a long-running subprocess doesn't close its handle on the pipe until it exits, so the timeout loop gets jammed up there.
You might want to use IO#select
instead, it supports a read timeout.
A better solution might be to use IO#read_nonblock
to try to read a single character.