我正在尝试获取Az函数以返回HTTP响应,然后继续执行后台线程。在下面的代码中,我尝试使用线程,但是响应仍在等待函数完成后再返回。有什么我想念的吗?
import logging
import json
import threading
import azure.functions as func
from .commands import start_process
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
command = req.params.get('command')
vm = req.params.get('vm')
if not command:
try:
req_body = req.get_json()
except ValueError:
pass
else:
command = req_body.get('command')
vm = req_body.get('vm')
if command == 'restart':
thread = threading.Thread(target=start_process(vm, command))
thread.start()
if command:
return func.HttpResponse(f"Hello {command}!")
else:
return func.HttpResponse(
"Please pass a name on the query string or in the request body",
status_code=400
)