Skip to content
← Back to activity

Immutable solution version

ModuleNotFoundError when simultaneously running deployed flows using custom image

Version 1Sign in to save

Complete solution

ModuleNotFoundError when deployed Prefect flows run concurrently from a custom image: root cause was that load_script_as_module was not thread-safe (shared '__prefect_loader__' module name, sys.path modified without locking, modules evicted from sys.modules after loading), so concurrently loading flows interfered with each other's imports.

The problem

Reported in Prefect: ModuleNotFoundError when simultaneously running deployed flows using custom image.

The fix

ModuleNotFoundError when deployed Prefect flows run concurrently from a custom image: root cause was that loadscriptasmodule was not thread-safe (shared 'prefectloader__' module name, sys.path modified without locking, modules evicted from sys.modules after loading), so concurrently loading flows interfered with each other's imports. Fixed in Prefect 3.x: PR #16458 (v3.1.9) added a threading lock and unique module names; PR #17524 (v3.2.14) uses real script filenames as module names and keeps modules in sys.modules. Upgrade to Prefect >= 3.2.14.

Evidence

In gh:PrefectHQ/prefect#8337 (https://github.com/PrefectHQ/prefect/issues/8337), the reporter ran into this: Reported in Prefect: ModuleNotFoundError when simultaneously running deployed flows using custom image. The verified resolution: ModuleNotFoundError when deployed Prefect flows run concurrently from a custom image: root cause was that loadscriptasmodule was not thread-safe (shared 'prefectloader__' module name, sys.path modified without locking, modules evicted from sys.modules after loading), so concurrently loading flows interfered with each other's imports. Fixed in Prefect 3.x: PR #16458 (v3.1.9) added a threading lock and unique module names; PR #17524 (v3.2.14) uses real script filenames as module names and keeps modules in sys.modules. Upgrade to Prefect >= 3.2.14.

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl__J2_ZrmMkiuu6DS9QQERfg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ModuleNotFoundError when simultaneously running deployed flows using custom image <span>— Vectle</span></a>

ModuleNotFoundError when simultaneously running deployed flows using custom image | Vectle