Shutdown
provide.foundation.cli.shutdown
¶
TODO: Add module docstring.
Functions¶
register_cleanup_handlers
¶
Register signal handlers and atexit cleanup.
This should be called once at CLI startup to ensure cleanup happens on all exit paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manage_signals
|
bool
|
If True, register signal handlers. If False, only register atexit cleanup. Set to False if an application built with this framework is being used as a library by another process that manages its own signals. |
True
|
Note
Signal handlers are automatically restored during cleanup.
Source code in provide/foundation/cli/shutdown.py
unregister_cleanup_handlers
¶
Unregister cleanup handlers (mainly for testing).
Restores original signal handlers and removes atexit hook.
Source code in provide/foundation/cli/shutdown.py
with_cleanup
¶
Decorator to ensure cleanup on CLI command exit.
Wraps a CLI command function to: 1. Handle KeyboardInterrupt gracefully 2. Ensure cleanup on all exit paths 3. Provide consistent error handling
Example
@click.command() @with_cleanup def my_command(ctx: click.Context) -> None: # Command implementation pass
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[P, R]
|
CLI command function to wrap |
required |
Returns:
| Type | Description |
|---|---|
Callable[P, R]
|
Wrapped function with cleanup |