Skip to content
This repository has been archived by the owner on Nov 23, 2018. It is now read-only.

Examples in README fail #19

Open
koudelka opened this issue Jul 23, 2013 · 1 comment
Open

Examples in README fail #19

koudelka opened this issue Jul 23, 2013 · 1 comment

Comments

@koudelka
Copy link

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
@koudelka
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant