Should I define an azure activity function as an async in python?

Jan Kowalik 105 Reputation points
2023-09-01T07:59:48.95+00:00

Azure functions documentation recommends defining python functions as asynchronous using the async keyword and async packages in the function body to take advantage of concurrent execution. See here.

I can not find any mention of the same for activity functions (those triggered with the activityTrigger) that are called by durable function orchestrators (using yield). See here.

Should I define an azure activity function as async in Python, as well? Why or why not?

Thank you in advance

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,029 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,466 Reputation points
    2023-09-01T11:50:43.58+00:00

    @Jan Kowalik Thanks for reaching out.

    Defining Python functions as asynchronous using the async keyword and async packages in the function body can help take advantage of concurrent execution. This is true for both orchestrator functions and activity functions. It is recommended to define them as asynchronous if you want to take advantage of concurrent execution. This is because activity functions can also perform I/O-bound operations, such as making network calls or accessing a database, which can benefit from asynchronous execution.

    In nutshell, it is recommended to define Azure activity functions as asynchronous in Python if you want to take advantage of concurrent execution and improve performance.

    Please "Accept Answer" if the answer is helpful so that it can help others in the community.


1 additional answer

Sort by: Most helpful
  1. Bosman, Marthinus 0 Reputation points
    2024-07-14T15:10:52.5633333+00:00

    The accepted answer is slightly incorrect. Activity functions can be async but the orchestrator function can not: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-code-constraints?tabs=python#python-coroutines

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.