We have a Azure Function at work that stopped working so I got tasked to debug it and found that it gets stuck in a timeout loop right of the bat. I don't have that much experience with Azure Functions so I thought perhaps a very basic function might work, but gets the same fault with that as well. Using Azurite for storage emulation.
Python 3.11.5, Azure.functions 1.17.0
This is my function:
import logging
import os
import azure.functions as func
# Create a custom logger
logger = logging.getLogger(__name__)
# Create handlers
f_handler = logging.FileHandler('file.log')
f_handler.setLevel(logging.DEBUG)
# Create formatters and add it to handlers
f_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
f_handler.setFormatter(f_format)
# Add handlers to the logger
logger.addHandler(f_handler)
logger.warning('This is a warning')
logger.error('This is an error')
def main(myblob: func.InputStream):
filename = os.path.basename(myblob.name)
content = myblob.read()
# Your code to process the blob content goes here
# For example, you can print the blob's filename and length
print(f"Blob name: {filename}")
print(f"Blob length: {len(content)} bytes")
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.0.0, 5.0.0)"
},
"singleton": {
"listenerLockPeriod": "00:00:15"
}
}
function.json
{
"scriptFile": "function_app.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "http://127.0.0.1:10000/devstoreaccount1/default/ECO_DAYINV904951960411607774_231019%20from%20231018.xlsx",
"source": "EventGrid",
"connection": "UseDevelopmentStorage=true"
}
]
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "http://localhost:7071/runtime/webhooks/blobs?functionName=Host.Functions.BlobTriggerEventGrid",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
I've tried to debug this, but can't get it to stop at a breakpoint, so I need to pause it and at that point it is already in the timeout loop in the common.py function.
I have created an Azure function with a blob trigger using runtime stack Python.
I have made some changes to your code and executed it successfully. function code:
loca.settings.json:
host.json:
function.json:
output:
When I put breakpoints in the code, I got hit in the code. check below: