in reply to CLI Interactivity - Timed Prompt
What's happening here is that the alarm() function arranges for an “alarm signal” to be sent to the program after a certain interval. The arrival of this signal causes an exception to be raised, which is caught by the eval construct.
The error-message for an alarm-timeout will contain the word “alarm,” and the error-checking code verifies that this is so. (Any other error is re-raised with die.)
This is a pretty-typical method of handling timeouts because as you can see, any time-consuming process can be interrupted by a signal ... and a poll/select socket-based program can easily handle it as well.
“alarms” are designed to be a fairly low-resolution timing mechanism.
Note: Don't forget to quash the alarm if you do get input from the user... otherwise the alarm will still come in “right on time,” probably with most-unfortunate consequences.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: CLI Interactivity - Timed Prompt
by viska (Acolyte) on Jan 25, 2008 at 19:57 UTC | |
|
Re^2: CLI Interactivity - Timed Prompt
by viska (Acolyte) on Jan 25, 2008 at 18:02 UTC |