question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable concurrent execution of Python functions

See original GitHub issue

I’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:

  1. The offending code is here: QueueWithHttpCall.zip. There is a function called QueueTriggerPython which pulls items from queues and triggers a GET request to an endpoint (from the IntakeHttpTrigger function).
  2. Activate virtual environment and install requirements: pip install -r requirements.txt.
  3. Install extensions: func extensions install
  4. Configure local.settings.json to point to the storage account that you are using.
  5. 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

  1. Both QueueTriggerPython and IntakeHttpTrigger are synchronous. Raise the number of workers in dispatcher.py to 2: https://github.com/Azure/azure-functions-python-worker/blob/6068092982479932f1d2d3c315ee6835cdeac8c1/azure/functions_worker/dispatcher.py#L56

  2. Both QueueTriggerPython and IntakeHttpTrigger 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:closed
  • Created 5 years ago
  • Comments:44 (24 by maintainers)

github_iconTop GitHub Comments

3reactions
polarapfelcommented, Mar 8, 2019

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!

3reactions
brettcannoncommented, Nov 19, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Multithreading and Multiprocessing Tutorial - Toptal
Threading is just one of the many ways concurrent programs can be built. In this article, we will take a look at threading...
Read more >
Concurrent Execution — Python 3.11.1 documentation
Concurrent Execution ¶ · The Process class · Contexts and start methods · Exchanging objects between processes · Synchronization between processes · Sharing...
Read more >
Speed Up Your Python Program With Concurrency
Concurrency is about design and modeling. Parallelism is about execution. The two ideas are orthogonal and are applied together to describe actual use...
Read more >
Concurrency in Python - Quick Guide - Tutorialspoint
Python 2 and 3 have large number of APIs dedicated for parallel/concurrent programming. Most popular of them are threading, concurrent.features, multiprocessing ...
Read more >
Python concurrency and parallelism explained - InfoWorld
Coroutines or async are a different way to execute functions concurrently in Python, by way of special programming constructs rather than system ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found