File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,12 @@ class LambdaRuntimeClient(object):
52
52
def __init__ (self , lambda_runtime_address , use_thread_for_polling_next = False ):
53
53
self .lambda_runtime_address = lambda_runtime_address
54
54
self .use_thread_for_polling_next = use_thread_for_polling_next
55
+ if self .use_thread_for_polling_next :
56
+ # Conditionally import only for the case when TPE is used in this class.
57
+ from concurrent .futures import ThreadPoolExecutor
58
+
59
+ # Not defining symbol as global to avoid relying on TPE being imported unconditionally.
60
+ self .ThreadPoolExecutor = ThreadPoolExecutor
55
61
56
62
def post_init_error (self , error_response_data ):
57
63
# These imports are heavy-weight. They implicitly trigger `import ssl, hashlib`.
@@ -74,9 +80,8 @@ def wait_next_invocation(self):
74
80
# which can then process signals.
75
81
if self .use_thread_for_polling_next :
76
82
try :
77
- from concurrent .futures import ThreadPoolExecutor
78
-
79
- with ThreadPoolExecutor (max_workers = 1 ) as executor :
83
+ # TPE class is supposed to be registered at construction time and be ready to use.
84
+ with self .ThreadPoolExecutor (max_workers = 1 ) as executor :
80
85
future = executor .submit (runtime_client .next )
81
86
response_body , headers = future .result ()
82
87
except Exception as e :
You can’t perform that action at this time.
0 commit comments