Azure function with python3.9: RuntimeError: can't start new thread Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py",

member45232 51 Reputation points
2022-09-04T20:48:39.673+00:00

This is the 2nd time that we see this and it is the 2nd issue within a week that seems to stem from the Microsoft Python runtime environment and being unrelated to our code. The traffic on our function is still pretty low.

First issue: https://learn.microsoft.com/en-us/answers/questions/984248/azure-function-with-pythonfastapi-sometimes-fails.html
It yet again causes outtages on production environment. Disappointing :-| Hope Microsoft can fix python functions.

Exception method

System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
Exception type

Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException
Exception message

Result: Failure
Exception: RuntimeError: can't start new thread
Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 403, in _handle__invocation_request
call_result = await self._run_async_func(
File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 655, in _run_async_func
return await ExtensionManager.get_async_invocation_wrapper(
File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py", line 147, in get_async_invocation_wrapper
result = await function(**args)
File "/home/site/wwwroot/app/main.py", line 93, in main
return func.AsgiMiddleware(fastapi_app).handle(req, context)
File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure/functions/_http_asgi.py", line 148, in handle
return self._handle(req, context)
File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure/functions/_http_asgi.py", line 154, in _handle
asgi_response = self._loop.run_until_complete(
File "/home/site/wwwroot/.python_packages/lib/site-packages/nest_asyncio.py", line 89, in run_until_complete
return f.result()
File "/usr/local/lib/python3.9/asyncio/futures.py", line 201, in result
raise self._exception
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 256, in step
result = coro.send(None)
File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure/functions/_http_asgi.py", line 67, in from_app
await app(scope, res._receive, res._send)
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastapi/applications.py", line 269, in __call

await super().call(scope, receive, send)
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/integrations/starlette.py", line 287, in _sentry_patched_asgi_app
return await middleware(scope, receive, send)
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/integrations/asgi.py", line 126, in _run_asgi3
return await self._run_app(scope, lambda: self.app(scope, receive, send))
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/integrations/asgi.py", line 173, in _run_app
_capture_exception(
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/integrations/asgi.py", line 57, in _capture_exception
hub.capture_event(event, hint=hint)
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/hub.py", line 336, in capture_event
rv = client.capture_event(event, hint, scope)
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/client.py", line 417, in capture_event
self.transport.capture_event(event_opt)
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/transport.py", line 456, in capture_event
if not self._worker.submit(send_event_wrapper):
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/worker.py", line 113, in submit
self._ensure_thread()
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/worker.py", line 42, in _ensure_thread
self.start()
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/worker.py", line 70, in start
self._thread.start()
File "/home/site/wwwroot/.python_packages/lib/site-packages/sentry_sdk/integrations/threading.py", line 54, in sentry_start
return old_start(self, *a, **kw)
File "/usr/local/lib/python3.9/threading.py", line 899, in start
_start_new_thread(self._bootstrap, ())

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,240 questions
{count} votes