0

I have an Azure Function which is triggered by a blobtrigger. So basically anytime somebody uploads a .csv to an Azure blobstorage I want to clean it up, process it, and insert it into an sql database table.

When I tested it out locally, it worked perfectly fine, but after deployment, I get errors like these: Exception while executing function: Functions.BlobTrigger1 python exited with code 137

I read that this exception is usually thrown when my function consumes too much memory, but I'm working with a .csv that has only 26.16 MiB. Here's my code

    blobBinaryDataStream = BytesIO(myblob.read())
    records = [r.decode('utf-8').split(',') for r in blobBinaryDataStream]
    arr = np.array(records)
    df = pd.DataFrame(arr[1:], columns=[name.replace('\r\n', '') for name in records[0]])
    df = df.replace('\r\n', '')
    del arr
    locationDF = df.iloc[: , [0, 1, 2, 46, 47, 48, 49, 50, 51, 58, 59, 60]].copy()
    locationDF.drop_duplicates(inplace=True)
    df.drop(df.columns.difference(df.columns[i] for i in [0, 3, 5, 8, 25, 35, 36]), axis = 1, inplace=True)
    df['date'] = df['date'].transform(lambda x: SomeFunction(x))
    df = df.replace('', 0)
    factdf = df.groupby([df.columns[0],df.columns[1]])[df.columns[2:]].apply(lambda x : x.astype(np.longlong).sum()).reset_index()
    
    quoted = urllib.parse.quote_plus(os.environ['ConnString'])
    engine = create_engine('mssql+pyodbc:///?odbc_connect={}'.format(quoted))

    locationDF.reset_index(drop=True, inplace=True)
    locationDF.index = locationDF.index + 1
    locationDF = locationDF.replace('', np.nan)
    locationDF.to_sql('Table1', schema='dbo', con=engine, if_exists='replace', method = 'multi', chunksize = 100)

    factdf.reset_index(drop=True, inplace=True)
    factdf.index = factdf.index + 1
    factdf.replace('', np.nan)
    factdf.to_sql('Table2', schema='dbo', con=engine, if_exists='replace', method = 'multi', chunksize = 100)
2
  • Well what is the memory metric in the Function App saying? Commented Sep 4, 2021 at 9:14
  • And how much memory this Function App has? Commented Sep 4, 2021 at 9:15

1 Answer 1

1

FunctionApp exits with error code as 137 which is caused by out-of-memory issues in your Python function app.

Have a look on the service limits in Microsoft Documentation based on the plans which you’ve chosen in your function app, I assume you’ve used Consumption plan.

Now to check whether it is timeout issue as it mentions 137 error code, keep an eye on Application Insights logs when your function app is executed.

In the errors if you find anything like “Timeout value of 00:05:00 exceeded by function”, then try to investigate about below points:

  1. Check why the code execution is taking more time, if you found any such scenarios then we can fix it from code itself.

  2. Increase the default timeout.

Below is how we can modify default timeout. By default, it will be as 5 minutes, we can increase it accordingly to check.

{
    "functionTimeout": "00:05:00"
}

Check the documentation for function timeout settings

functionTimeout indicated the timeout duration for all the functions and not for the single function.

You can update the default timeout value, save it, and test your function again.

Also refer to the documentation about Memory profiling on Python function apps to understand more about managing the memory in our functions.

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.