Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
331 stars 100 forks source link

Graceful shutdown when using the Python worker #1521

Open bastbu opened 3 days ago

bastbu commented 3 days ago

Is your question related to a specific version? If so, please specify:

The question is not related to a specific version.

What binding does your question apply to, if any? (e.g. Blob Trigger, Event Hub Binding, etc)

HTTP trigger

Question

The best practices for Azure Functions mention that we should reuse global client instances for better performance with connection pooling. One example also demonstrates the use of a global Cosmos client instance as a pattern.

However, with these global instances, there should be a way to close the connections on a graceful shutdown, prior to stopping the worker.

Another use-case would be to make sure that all telemetry is flushed before the host is (gracefully) shutting down.

Is there any existing documentation that I missed which would explain how to do this in Python? If not, could you provide guidance on how this should be implemented?