Application Events#
Panther provides a simple way to execute custom logic during your application's lifecycle using event decorators. You can hook into the startup and shutdown phases to run code when your app starts or stops.
Startup Event#
To run code when your application starts, use the @Event.startup
decorator:
events.py | |
---|---|
1 2 3 4 5 |
|
You can define multiple startup event handlers. They will be executed in the order they are registered.
Shutdown Event#
To run code when your application is shutting down, use the @Event.shutdown
decorator:
events.py | |
---|---|
1 2 3 4 5 |
|
You can define multiple shutdown event handlers as well.
Additional Notes#
- Multiple Handlers: You can register multiple functions for both
startup
andshutdown
events. All will be called. - Sync & Async Support: Event handlers can be either synchronous or asynchronous functions.
- Use Cases: Common use cases include initializing resources (like database connections) on startup and cleaning up resources on shutdown.