module Signal
Signals: Signal.trap(:TERM) { } runs the block on a task of its own
when the signal arrives (the signal handler only notes it).
The signals are :HUP, :INT, :QUIT, :USR1, :USR2, :PIPE and
:TERM, also named as strings, with or without the "SIG" prefix.
SIGPIPE is ignored from the start, so that writing to a closed socket or
pipe raises SystemCallError instead of ending the program.
stop = Channel[Bool].new(capacity: 1)
Signal.trap(:TERM) { stop.try_send(true) }
Signal.trap(:INT) { stop.try_send(true) }
stop.receive # waits; the other tasks go on
puts "shutting down"
<prelude>:6481
Constants
TRAPS: Atom[Hash[Int, Array[shareable () -> Void]]]
The traps by signal number, in the order they were set.
<prelude>:6498
Class methods
def self.number(name: String) -> Int?
The number of the signal name ("TERM" or "SIGTERM", in capitals),
or nil for a signal trap does not take.
<prelude>:6484
def self.names -> Array[String]
The names of the signals trap takes, without the "SIG" prefix.
<prelude>:6486
def self.list -> Hash[String, Int]
The signals trap takes, with their numbers.
<prelude>:6501
def self.trap(name: Symbol, &handler: shareable () -> Void) -> Void
Runs handler whenever the signal name (:TERM, "SIGTERM")
arrives.
The traps replace the signal's default action: the program no longer
ends on a trapped SIGINT or SIGTERM. A new trap is added to the ones
set before: each arrival starts a task for each trap of the signal, in
no particular order. An exception a handler raises is printed to
standard error. The handler captures by value, as a Task.spawn block
does. Signals that arrive in a burst may run the traps only once.
Raises
ArgumentError for a signal not in .names (:KILL).
<prelude>:6520
def self.trap(name: String, &handler: shareable () -> Void) -> Void
Runs handler whenever the signal name (:TERM, "SIGTERM")
arrives.
The traps replace the signal's default action: the program no longer
ends on a trapped SIGINT or SIGTERM. A new trap is added to the ones
set before: each arrival starts a task for each trap of the signal, in
no particular order. An exception a handler raises is printed to
standard error. The handler captures by value, as a Task.spawn block
does. Signals that arrive in a burst may run the traps only once.
Raises
ArgumentError for a signal not in .names (:KILL).
<prelude>:6523
def self.trap(name: Symbol, action: Symbol) -> Void
:default restores the default action, :ignore ignores the signal;
either drops the traps.
Raises
ArgumentError for a signal not in .names, for another action, and
for :default on :PIPE (which stays ignored).
<prelude>:6542
def self.trap(name: String, action: Symbol) -> Void
:default restores the default action, :ignore ignores the signal;
either drops the traps.
Raises
ArgumentError for a signal not in .names, for another action, and
for :default on :PIPE (which stays ignored).
<prelude>:6545