6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fun_ci/pipeline/process_runner.rb', line 6
def run_process_with_timeout(cmd, budget)
r, w = IO.pipe
pid = Process.spawn(cmd, out: w, err: w, pgroup: true)
w.close
reader = Thread.new { r.read }
if reader.join(budget)
output = reader.value
_, status = Process.waitpid2(pid)
[output, status, false]
else
Process.kill("TERM", -pid) rescue nil
Process.kill("KILL", -pid) rescue nil
Process.waitpid(pid) rescue nil
["", nil, true]
end
ensure
r&.close rescue nil
end
|