Azure Function Error 线程中没有当前事件循环

Azure Function Error There is no current event loop in thread

我有一个 python Azure 函数已经 运行 几个月了。在 7 月 23 日,它开始失败并出现错误 There is no current event loop in thread.

我将 post 相关的代码位:

init.py 中我创建了一个 JSON 事件然后调用: '''

run_func(event)

'''

run_func 函数如下所示: '''

def run_func(event):
    print("Running Start")
    query = "Sites "              
    client = KustoClient(kcsb)

'''

失败在上面显示的最后一行。我已经将 azure.kusto.data 包更新到最新版本。每次都失败并出现相同的错误。

我会 post 完整的错误在这里:

2021-07-30T00:00:42.188890984Z ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException:结果:失败 2021-07-30T00:00:42.188893884Z 异常:RuntimeError:线程 'ThreadPoolExecutor-0_0' 中没有当前事件循环。 2021-07-30T00:00:42.188896584Z 堆栈:文件“/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py”,第 398 行,在 _handle__invocation_request 中 2021-07-30T00:00:42.188899484Z call_result = 等待 self._loop.run_in_executor( 2021-07-30T00:00:42.188901784Z 文件“/usr/local/lib/python3.8/concurrent/futures/thread.py”,第 57 行,在 运行 中 2021-07-30T00:00:42.188904284Z 结果 = self.fn(*self.args, **self.kwargs) 2021-07-30T00:00:42.188906784Z 文件“/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py”,第 602 行,在 _run_sync_func 中 2021-07-30T00:00:42.188910284Z return ExtensionManager.get_sync_invocation_wrapper(上下文, 2021-07-30T00:00:42.188913984Z 文件“/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/extension.py”,第 215 行,在 _raw_invocation_wrapper 中 2021-07-30T00:00:42.188918084Z 结果 = 函数(**参数) 2021-07-30T00:00:42.188921384Z 文件“/home/site/wwwroot/TimerTrigger1/init.py”,第 24 行,在主 2021-07-30T00:00:42.188924985Z run_func(事件) 2021-07-30T00:00:42.188928585Z 文件“/home/site/wwwroot/TimerTrigger1/soofie_azure.py”,第 1281 行,在 run_func 中 2021-07-30T00:00:42.188931185Z 客户端 = KustoClient(kcsb) 2021-07-30T00:00:42.188944585Z 文件“/home/site/wwwroot/.python_packages/lib/site-packages/azure/kusto/data/client.py”,第 763 行,在 init 中 2021-07-30T00:00:42.188948785Z self._auth_provider = _AadHelper(self._kcsb) 如果 self._kcsb.aad_federated_security 否则 None 2021-07-30T00:00:42.188953185Z 文件“/home/site/wwwroot/.python_packages/lib/site-packages/azure/kusto/data/security.py”,第 23 行,在 init 中 2021-07-30T00:00:42.18895578​​5Z self.token_provider = ApplicationKeyTokenProvider(self.kusto_uri, kcsb.authority_id, kcsb.application_client_id, kcsb.application_key) 2021-07-30T00:00:42.188958385Z 文件“/home/site/wwwroot/.python_packages/lib/site-packages/azure/kusto/data/_token_providers.py”,第 485 行,在 init 中 2021-07-30T00:00:42.188960885Z super().init(kusto_uri) 2021-07-30T00:00:42.188963685Z 文件“/home/site/wwwroot/.python_packages/lib/site-packages/azure/kusto/data/_token_providers.py”,第 69 行,在 init 中 2021-07-30T00:00:42.188966285Z self._async_lock = asyncio.Lock() 2021-07-30T00:00:42.188968585Z 文件“/usr/local/lib/python3.8/asyncio/locks.py”,第 164 行,在 init 中 2021-07-30T00:00:42.188971485Z self._loop = events.get_event_loop() 2021-07-30T00:00:42.188974985Z 文件“/usr/local/lib/python3.8/asyncio/events.py”,第 639 行,在 get_event_loop 中 2021-07-30T00:00:42.188978885Z 引发运行时错误('There is no current event loop in thread %r.'

这是版本 2.3.0 中的一个已知错误

2.3.1 将很快发布并修复,同时作为解决方法,您可以使用 2.2.1