Enable concurrent execution of Python functions
See original GitHub issueI’ve managed to isolate an issue where a queue trigger function is unable to call an http endpoint from a function with the same app. This behavior manifests when the functions are synchronous or asynchronous.
Repro steps
Provide the steps required to reproduce the problem:
- The offending code is here: QueueWithHttpCall.zip. There is a function called
QueueTriggerPython
which pulls items from queues and triggers aGET
request to an endpoint (from theIntakeHttpTrigger
function). - Activate virtual environment and install requirements:
pip install -r requirements.txt
. - Install extensions:
func extensions install
- Configure
local.settings.json
to point to the storage account that you are using. - Run
func host start
and then add item to the configured queue.
Expected behavior
The queue trigger should be able to successfully call into the HTTP endpoint and return the correct status code as well as print out the log message to the console.
Actual behavior
The queue trigger is activated but hangs when trying to call the HTTP endpoint, getting stuck at the following point:
Executing 'Functions.IntakeHttpTrigger' (Reason='This function was programmatically called via the host APIs.', Id=411d2a47-71de-4ab1-b231-c99a9794a7cb)
This is after the point at which the host calls into the language worker to process the request.
Known workarounds
-
Both
QueueTriggerPython
andIntakeHttpTrigger
are synchronous. Raise the number of workers indispatcher.py
to 2: https://github.com/Azure/azure-functions-python-worker/blob/6068092982479932f1d2d3c315ee6835cdeac8c1/azure/functions_worker/dispatcher.py#L56 -
Both
QueueTriggerPython
andIntakeHttpTrigger
are asynchronous. No known workarounds.
Related information
For the sync case, there appears to be some issue with the worker threads which are blocking themselves rather than processing the request from a function in the same app. This would explain why raising the number of thread workers to 2 caused the call to go through (one thread for queue trigger and one for the subsequent http call it makes). For the async case, it might be a manifestation of a similar issue since we are executing in the main event loop rather than using a separate thread pool.
Issue Analytics
- State:
- Created 5 years ago
- Comments:44 (24 by maintainers)
Top GitHub Comments
This is one of the most insightful issue discussions I’ve come across in a while. Thanks to everyone providing their insights and reasoning. I would really appreciate if part of the outcome of this issue is taking agreed upon insights and position these as guidance in the documentation for Python Azure Functions developers. Thanks!
Since I was cc’ed I will say my opinion is to agree with Elvis and say to not up the number of workers and push users towards
async
/await
to both keep the worker simpler and to help users not shoot themselves in the foot with threaded code.