Azure / Azure/azure-functions-python-worker

Graceful shutdown when using the Python worker

Open
#1,521 1 comment 7 reactions 0 assignees View on GitHub
area:python-functions python
Dominant language
Python
Stars
357
Forks
116
Avg merge
32m
Merged PRs (30d)
1

Description

#### 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](https://learn.microsoft.com/azure/azure-functions/manage-connections?tabs=csharp#static-clients) 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](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators#connect-to-a-database) 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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.