Limits: Graceful Cancellation and Timeout Support in Rexx's SIGNAL ON HALT
0 reputation · 09 Aug 2022, 13:34 UTC
0 reputation · 09 Aug 2022, 13:34 UTC
The Rexx language provides a SIGNAL ON HALT clause to trap asynchronous interrupt requests such as Ctrl+C. However, the standard does not define a portable timeout for blocking operations like ADDRESS host commands or I/O, and the behavior of a trapped HALT varies across Classic, Open Object, and Regina Rexx. When a long-running host call is interrupted, some interpreters resume execution after the handler, while others terminate the program or ignore subsequent interrupts.
Because there is no built‑in, cross‑implementation timeout mechanism, developers must rely on implementation‑specific extensions or external process control to achieve graceful cancellation and timeouts.
What are the documented limits of SIGNAL ON HALT regarding resumption after a trap, and how do different Rexx interpreters implement this behavior? How can a script enforce a timeout on a blocking ADDRESS call without relying on non‑portable extensions? What best practices exist for cleaning up resources or external subprocesses when a HALT trap is invoked?
35775 reputation · 09 Aug 2022, 21:23 UTC
The SIGNAL ON HALT clause allows a Rexx program to trap asynchronous interrupts (such as Ctrl+C). However, the primary limit is that resumption is not guaranteed to be immediate during blocking operations. Because Rexx often delegates ADDRESS calls to the host operating system, the interpreter may not regain control to execute the trap handler until the external process returns control to the interpreter.
Behavior varies across the three major interpreter families:
There is no portable, built-in Rexx keyword for timeouts. To enforce a timeout without using non-portable extensions, you must shift the timeout logic from the Rexx interpreter to the host command itself.
Instead of calling a command directly, wrap the command in a host-level utility that supports timeouts. For example:
timeout command (e.g., ADDRESS CMD "timeout 10s my_script.sh").-TimeoutSec parameter.By handling the timeout at the OS level, the host command returns a specific exit code to Rexx, which can then be evaluated using RC to trigger a graceful failure.
To ensure external subprocesses or files are cleaned up when a HALT trap is invoked, follow these patterns:
SIGNAL ON HALT handler to call this cleanup routine and then explicitly EXIT or LEAVE to prevent the program from resuming in an unstable state.Verification: To verify behavior in your specific environment, run a script with a long ADDRESS sleep command (e.g., ADDRESS CMD "sleep 30") and trigger a HALT signal. If the handler does not execute until the sleep finishes, your environment cannot interrupt blocking host calls.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.