Skip to content

Commit f53de62

Browse files
committed
Remove hasattr check for every invocation
1 parent 7fde853 commit f53de62

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

workers/proxy_worker/dispatcher.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
# Library worker import reloaded in init and reload request
3939
_library_worker = None
40+
_library_worker_has_cv = False
4041

4142
# Thread-local invocation ID registry for efficient lookup
4243
_thread_invocation_registry: typing.Dict[int, str] = {}
@@ -99,9 +100,9 @@ def get_global_current_invocation_id() -> Optional[str]:
99100

100101

101102
def get_current_invocation_id() -> Optional[Any]:
102-
global _library_worker
103+
global _library_worker, _library_worker_has_cv
103104
# Check global current invocation first (most up-to-date)
104-
if _library_worker and not hasattr(_library_worker, 'invocation_id_cv'):
105+
if _library_worker and not _library_worker_has_cv:
105106
global_invocation_id = get_global_current_invocation_id()
106107
if global_invocation_id is not None:
107108
return global_invocation_id
@@ -404,12 +405,13 @@ def stop(self) -> None:
404405

405406
@staticmethod
406407
def reload_library_worker(directory: str):
407-
global _library_worker
408+
global _library_worker, _library_worker_has_cv
408409
v2_scriptfile = os.path.join(directory, get_script_file_name())
409410
if os.path.exists(v2_scriptfile):
410411
try:
411412
import azure_functions_runtime # NoQA
412413
_library_worker = azure_functions_runtime
414+
_library_worker_has_cv = hasattr(_library_worker, 'invocation_id_cv')
413415
logger.debug("azure_functions_runtime import succeeded: %s",
414416
_library_worker.__file__)
415417
except ImportError:
@@ -419,6 +421,7 @@ def reload_library_worker(directory: str):
419421
try:
420422
import azure_functions_runtime_v1 # NoQA
421423
_library_worker = azure_functions_runtime_v1
424+
_library_worker_has_cv = hasattr(_library_worker, 'invocation_id_cv')
422425
logger.debug("azure_functions_runtime_v1 import succeeded: %s",
423426
_library_worker.__file__) # type: ignore[union-attr]
424427
except ImportError:

0 commit comments

Comments
 (0)