Module: Polyphony::Process
- Defined in:
- lib/polyphony/adapters/process.rb
Overview
Process extensions
Class Method Summary collapse
-
.kill_process(pid) ⇒ Object
Kills the given pid, waiting for it to terminate, with a timeout of 5 seconds.
-
.watch(cmd = nil, &block) ⇒ true
Watches a forked or spawned process, waiting for it to terminate.
Class Method Details
.kill_process(pid) ⇒ Object
Kills the given pid, waiting for it to terminate, with a timeout of 5 seconds.
30 31 32 33 34 35 36 |
# File 'lib/polyphony/adapters/process.rb', line 30 def kill_process(pid) cancel_after(5) do kill_and_await('TERM', pid) end rescue Polyphony::Cancel kill_and_await(-9, pid) end |
.watch(cmd = nil, &block) ⇒ true
Watches a forked or spawned process, waiting for it to terminate. If
cmd
is given it is spawned, otherwise the process is forked with the
given block.
If the operation is interrupted for any reason, the spawned or forked process is killed.
17 18 19 20 21 22 23 24 |
# File 'lib/polyphony/adapters/process.rb', line 17 def watch(cmd = nil, &block) terminated = nil pid = cmd ? Kernel.spawn(cmd) : Polyphony.fork(&block) Polyphony.backend_waitpid(pid) terminated = true ensure kill_process(pid) unless terminated || pid.nil? end |