# `cement.ext.ext_alarm`

The Alarm Extension provides easy access to setting an application alarm to handle timing out operations. See the Python Signal Library.

## Requirements

> - No external dependencies.
> - Only available on Unix/Linux

## Configuration

This extension does not honor any application configuration settings.

## Usage

    import time
    from cement.core.foundation import CementApp
    from cement.core.exc import CaughtSignal

    class MyApp(CementApp):
        class Meta:
            label = 'myapp'
            exit_on_close = True
            extensions = ['alarm']

    with MyApp() as app:
        try:
            app.run()
            app.alarm.set(3, "The operation timed out after 3 seconds!")

            # do something that takes time to operate
            time.sleep(5)

            app.alarm.stop()

        except CaughtSignal as e:
            print(e.msg)
            app.exit_code = 1

Looks like:

    $ python myapp.py
    ERROR: The operation timed out after 3 seconds!
    Caught signal 14

class `cement.ext.ext_alarm.``AlarmManager`(*args, **kw)

  Bases: `object`

  Lets the developer easily set and stop an alarm. If the alarm exceeds the given time it will raise `signal.SIGALRM`.

  `set`(time, msg)

    Set the application alarm to `time` seconds. If the time is exceeded `signal.SIGALRM` is raised.

    Parameters:

    - time – The time in seconds to set the alarm to.
    - msg – The message to display if the alarm is triggered.

  `stop`()

    Stop the application alarm.