From 411ea4f19c7d13e72a22dd8be19ed64534ef87e5 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 23 Dec 2024 15:24:49 +1300 Subject: [PATCH] Improved signal handling. --- lib/async/container/controller.rb | 14 +++++++------- lib/async/container/group.rb | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/async/container/controller.rb b/lib/async/container/controller.rb index 6484d17..df24c16 100644 --- a/lib/async/container/controller.rb +++ b/lib/async/container/controller.rb @@ -205,13 +205,13 @@ def run end end end - rescue Interrupt - self.stop - rescue Terminate - self.stop(false) - ensure - self.stop(false) end + rescue Interrupt + self.stop + rescue Terminate + self.stop(false) + ensure + self.stop(false) end private def with_signal_handlers @@ -233,7 +233,7 @@ def run ::Thread.current.raise(Hangup) end - ::Thread.handle_interrupt(SignalException => :on_blocking) do + ::Thread.handle_interrupt(SignalException => :never) do yield end ensure diff --git a/lib/async/container/group.rb b/lib/async/container/group.rb index 82a844a..17271c5 100644 --- a/lib/async/container/group.rb +++ b/lib/async/container/group.rb @@ -150,6 +150,7 @@ def wait_for_children(duration = nil) end end + # Wait for a child process to exit OR a signal to be received. def select(duration) ::Thread.handle_interrupt(SignalException => :immediate) do readable, _, _ = ::IO.select(@running.keys, nil, nil, duration)