Module: LLM::Tool::Utils::Process
- Defined in:
- lib/llm/tools/utils/process.rb
Instance Method Summary collapse
-
#wait(command:, timeout:)
This method waits for a command to finish but within timeout.
-
#spawn(command:, arguments:, env: {}, max_bytes: self.class.max_bytes) ⇒ LLM::Command
Spawn a command from a command and arguments, without going through a shell.
- #now ⇒ Numeric
Instance Method Details
#wait(command:, timeout:)
Note:
When the timeout expires this method
will throw :kill rather than raise
an exception.
This method returns an undefined value.
This method waits for a command to finish but within timeout. A timeout that expires will throw back to the caller.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/llm/tools/utils/process.rb', line 18 def wait(command:, timeout:) start = now while command.running? || status_unavailable?(command) if now - start > timeout command.kill! throw(:kill, true) end sleep 0.01 end end |
#spawn(command:, arguments:, env: {}, max_bytes: self.class.max_bytes) ⇒ LLM::Command
Spawn a command from a command and arguments,
without going through a shell. The command's
stdout and stderr are each capped at max_bytes.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/llm/tools/utils/process.rb', line 45 def spawn(command:, arguments:, env: {}, max_bytes: self.class.max_bytes) if Integer(max_bytes, exception: false).nil? raise ArgumentError, "max_bytes cannot be nil" end LLM::Command .new(command) .env(env) .arguments(*[*arguments]) .limit(stdout: max_bytes, stderr: max_bytes) .spawn end |
#now ⇒ Numeric
59 60 61 |
# File 'lib/llm/tools/utils/process.rb', line 59 def now ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) end |