我可以创建一个 Azure Functions 项目 (V2) - Python 3.11 发布所有函数后,它们都可以在我的本地开发笔记本电脑上运行,但是有一个函数在作为 Azure 函数托管时无法运行。
造纸厂..
我已经下载了 python 文件,我可以验证它是否位于 Azure Function 下载文件的 tmp 文件夹中,并且我在那里有元数据文件 < - same as when debugging locally.
但是,当我在 papermill 中调用execute_notebook 函数时,我立即收到此错误?
内核在回复 kernel_info 之前就死掉了
这是什么意思?在托管的 Azure Function 上运行时如何使其工作?
您需要通过访问Azure Function应用程序中的
Advance tool kudu
和SSH'ing
来安装内核。确保 您已在高级或专用应用程序服务计划中创建了 Azure Function 应用程序,以便 ssh 正常工作:-
我的函数应用程序 kudu ssh 命令来安装内核:-
pip install ipykernel
python -m ipykernel install --user --name jupytersiddhesh
Azure function app > Development Tools > Advanced Tools > Go:-
我的函数应用程序代码:-
import azure.functions as func
import logging
import papermill as pm
import tempfile
import os
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="http_trigger")
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
name = req_body.get('name')
except ValueError:
pass
if name:
temp_dir = tempfile.mkdtemp()
input_notebook = os.path.join(temp_dir, "input_notebook.ipynb")
output_notebook = os.path.join(os.getenv('HOME', 'D:\\home\\data\\temp'), "output_notebook.ipynb")
with open(input_notebook, 'w') as file:
file.write("""
# Sample Notebook
print(f'Hello, {name}. This is a sample notebook execution.')
""")
pm.execute_notebook(
input_path=input_notebook,
output_path=output_notebook,
parameters=dict(name=name),
kernel_name='jupytersiddhesh'
)
with open(output_notebook, 'r') as file:
output_content = file.read()
return func.HttpResponse(output_content, status_code=200)
else:
return func.HttpResponse(
"Please provide 'name' parameter.",
status_code=400
)
请参阅我的SO回答