From c4f7a8412c8abb245fb3a422888db68a9881a823 Mon Sep 17 00:00:00 2001 From: Neil Ketteringham <53205839+Neilk1021@users.noreply.github.com> Date: Fri, 31 Jul 2026 18:53:44 +0000 Subject: [PATCH] fix(pyamber): Invalidate cache while loading executor_def. (#7173) ### What changes were proposed in this PR? This PR calls `importlib.invalidate_caches()` prior to importing newly written UDF modules in `ExecutorManager.load_executor_definition`. ### Any related issues, documentation, discussions? Fixes #7126 ### How was this PR tested? Tested with existing Python unit tests: * `amber/src/test/python/core/architecture/managers/test_executor_manager.py::TestUpdateExecutor::test_repeated_updates_keep_carrying_the_running_state` Verified that rapid sequential executor updates cleanly load without throwing `ModuleNotFoundError`. ### Was this PR authored or co-authored using generative AI tooling? No. (backported from commit 24a20c8e4b6f876082be35f6f5fba4833a122de8) --- .../main/python/core/architecture/managers/executor_manager.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/amber/src/main/python/core/architecture/managers/executor_manager.py b/amber/src/main/python/core/architecture/managers/executor_manager.py index 7f2249476ad..375033ad60c 100644 --- a/amber/src/main/python/core/architecture/managers/executor_manager.py +++ b/amber/src/main/python/core/architecture/managers/executor_manager.py @@ -99,6 +99,9 @@ def load_executor_definition(self, code: str) -> type(Operator): f"{Path(self.fs.getsyspath('/')).joinpath(file_name)}." ) + # Clear importlib's directory listing cache so freshly written + # temporary modules are discoverable on systems with coarse mtime. + importlib.invalidate_caches() # gen_module_file_name guarantees module_name is unique across # the process, so import_module will always cleanly load source # from the tmp fs we just wrote — no re-import / reload dance.