.. _examples.extra.shutdown_handling:

Shutdown Handling
=================

To drastically improve SDKS's performance, we spawn an additional thread with its event pool (asyncio).
But because the non-main thread cannot be listening to signals like SIGINT/SIGTERM, we need the owner of the
main thread to do so; this is why we provide the 'handle_shutdown_event' function, which allows you to signalise
the termination action to the SDK.

.. literalinclude:: ../../../examples/extra/shutdown_handling.py
	:language: python
	:caption: See `shutdown_handling.py <https://github.com/IBM/ibm-generative-ai/blob/v2.3.0/examples/extra/shutdown_handling.py>`_ on GitHub.
	:lines: 10-