Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix runtime_client blocking main thread
runtime_client.next is calling into the C extension which blocks the
main thread. Moving it to a separate thread enables the main thread
to process signal, see this issue for more details: #105
  • Loading branch information
Tiangang Song
Tiangang Song authored Sep 14, 2023
commit 20715b6e5dda6705d95aea196207c576ad3f0d27
5 changes: 4 additions & 1 deletion awslambdaric/lambda_runtime_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import http
import http.client
import sys
from concurrent.futures import ThreadPoolExecutor
from awslambdaric import __version__


Expand Down Expand Up @@ -65,7 +66,9 @@ def post_init_error(self, error_response_data):
raise LambdaRuntimeClientError(endpoint, response.code, response_body)

def wait_next_invocation(self):
response_body, headers = runtime_client.next()
with ThreadPoolExecutor() as e:
fut = e.submit(runtime_client.next)
response_body, headers = fut.result()
return InvocationRequest(
invoke_id=headers.get("Lambda-Runtime-Aws-Request-Id"),
x_amzn_trace_id=headers.get("Lambda-Runtime-Trace-Id"),
Expand Down