0

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.

1 Answer 1

1

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:

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)
 
def main(myblob: func.InputStream):
    # Log a message
    logger.info(f"Python blob trigger function processed blob\n"
                f"Name: {myblob.name}\n"
                f"Blob Size: {myblob.length} bytes")
 
    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")

loca.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "your connection string",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "storepavan3_STORAGE": "your connection string"
  }
}

host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  },
  "concurrency": {
    "dynamicConcurrencyEnabled": true,
    "snapshotPersistenceEnabled": true
  }
}

function.json:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "samples-workitems/{name}",
      "connection": "storepavan3_STORAGE"
    }
  ]
}

output: enter image description here

When I put breakpoints in the code, I got hit in the code. check below:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.