Class: Ibex::BoundedSubprocess
- Inherits:
-
Object
- Object
- Ibex::BoundedSubprocess
- Defined in:
- lib/ibex/bounded_subprocess.rb
Overview
Captures one shell-free child process under wall-clock and output budgets.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- DEFAULT_TIMEOUT_SECONDS =
: Integer
10- DEFAULT_MAX_OUTPUT_BYTES =
: Integer
1_048_576- TERMINATION_GRACE_SECONDS =
: Float
0.25- POLL_SECONDS =
: Float
0.01
Instance Method Summary collapse
-
#initialize(timeout_seconds: DEFAULT_TIMEOUT_SECONDS, max_output_bytes: DEFAULT_MAX_OUTPUT_BYTES) ⇒ BoundedSubprocess
constructor
A new instance of BoundedSubprocess.
- #run(command, input:) ⇒ Object
Constructor Details
#initialize(timeout_seconds: DEFAULT_TIMEOUT_SECONDS, max_output_bytes: DEFAULT_MAX_OUTPUT_BYTES) ⇒ BoundedSubprocess
Returns a new instance of BoundedSubprocess.
35 36 37 38 39 40 41 42 |
# File 'lib/ibex/bounded_subprocess.rb', line 35 def initialize(timeout_seconds: DEFAULT_TIMEOUT_SECONDS, max_output_bytes: DEFAULT_MAX_OUTPUT_BYTES) raise ArgumentError, "timeout_seconds must be positive" unless timeout_seconds.positive? raise ArgumentError, "max_output_bytes must be positive" unless max_output_bytes.positive? @timeout_seconds = timeout_seconds @max_output_bytes = max_output_bytes end |
Instance Method Details
#run(command, input:) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ibex/bounded_subprocess.rb', line 45 def run(command, input:) raise ArgumentError, "command must not be empty" if command.empty? Tempfile.create("ibex-subprocess-input") do |stdin| Tempfile.create("ibex-subprocess-stdout") do |stdout| Tempfile.create("ibex-subprocess-stderr") do |stderr| run_with_files(command, input, stdin, stdout, stderr) end end end end |