LogoLogo
Official SiteAPI Reference
stable/3.0
stable/3.0
  • Cement Developer Guide
  • Release Information
    • What's New!
    • Upgrading
    • ChangeLog
    • Deprecations
  • Getting Started
    • Installation
    • Developer Tools
    • Framework Overview
    • Beginner Tutorial
      • Part 1: Creating Your First Project
      • Part 2: Adding Features
      • Part 3: Extending a Project
      • Part 4: Making Everything Legit
  • Core Foundation
    • Interfaces and Handlers
    • Hooks
    • Configuration Settings
    • Arguments
    • Logging
    • Controllers
    • Output Rendering
    • Caching
    • Mail Messaging
    • Framework Extensions
    • Application Plugins
    • Templating
  • Utilities
    • Filesystem
    • Shell
    • Miscellaneous
  • Extensions
    • Alarm
    • Argparse
    • Colorlog
    • ConfigParser
    • Daemon
    • Dummy
    • Generate
    • Jinja2
    • Json
    • Logging
    • Memcached
    • Mustache
    • Plugin
    • Print
    • Redis
    • Scrub
    • SMTP
    • Tabulate
    • Yaml
    • Watchdog
  • Additional Topics
    • Extending The App Object
    • Unit Testing
    • Cleanup
    • Signal Handling
    • Pipenv
    • Autocomplete
    • Profiling with cProfile
    • Debugging with VSCode
  • Environment Variables
  • Terminology
  • Contributing
  • Privacy Policy
Powered by GitBook
On this page
  • Introduction
  • Requirements
  • Platform Support
  • Configuration
  • Usage
  1. Extensions

Alarm

PreviousExtensionsNextArgparse

Last updated 2 years ago

Introduction

The Alarm Extension provides the extended object, with easy mechanisms for handling long running operations that might timeout after a set amount of time.

API References:

Requirements

  • No external dependencies

As of Cement 3.0.8, applications using optional extensions should include them in their dependencies for future compatibility in the event additional dependencies are required:

Ex: cement[alarm]

Platform Support

  • Unix

  • Linux

  • macOS (Darwin)

Configuration

This extension does not rely on any application level configuration settings or meta options.

Usage

import time
from cement import App, CaughtSignal

class MyApp(App):
    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
$ python myapp.py
ERROR: The operation timed out after 3 seconds!
Caught signal 14
AlarmManager
Cement Alarm Extension
Python Signal Library