Skip to main content

A flexible context manager for python to handle graceful termination of python programs

Project description

Python Graceful Exit Context Manager

A flexible context manager for python to handle graceful termination of python programs

Installation

pip install -U graceful-exit

How to use:

Synchronous example

from graceful_exit.module import GracefulExit
from graceful_exit.helpers import wrap_in_system_exit

def main():
    app = App()
    with GracefulExit[App](
        app=app, exit_handler=app.exit_handler_sync
    ) as wrapped_app:
        wrapped_app.run_sync()

if __name__ == "__main__":
    wrap_in_system_exit(main())

Asynchronous example

from graceful_exit.module import GracefulExit
from graceful_exit.helpers import wrap_in_system_exit

async def main():
    app = App()
    async with GracefulExit[App](
        app=app, exit_handler=app.exit_handler_async
    ) as wrapped_app:
        await wrapped_app.run_async()

if __name__ == "__main__":
    wrap_in_system_exit(asyncio.run(main()))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graceful-exit-1.0.0.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file graceful-exit-1.0.0.tar.gz.

File metadata

  • Download URL: graceful-exit-1.0.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for graceful-exit-1.0.0.tar.gz
Algorithm Hash digest
SHA256 126b8358a1bf155b960de18c6553393a366c0a9410c41276e4a34cce74ad6c9b
MD5 9ea30569c91ee9fb456b298d322d860e
BLAKE2b-256 13953c4c418963f6a0a505c24fc18235c29a6995d752702d2e8f14239d124d5f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page