Loader waits for a module another thread is still importing (issue #132, BUG-1482 reopened)
Independent Staging Quality Gate / validate (push) Successful in 16m40s
Independent Staging Quality Gate / publish (push) Successful in 4m32s

Gate run 5888 failed: the synastry full dossier computes two full readings
on a thread pool, and the second thread got jyotish_engine from sys.modules
while the first was still executing it (no cmd_full_reading yet). Reuse now
goes through importlib.import_module, which waits on the module lock.

Four threads loading one module in a fresh interpreter: before
[False, True, True, True], after all True three times. Dossier scenario
before 4/4 AttributeError, after 6/6 ok; synastry-full-report.test.ts 17/17.
Ledger ERR-117: local npm baseline hid it (system python3 lacks swisseph).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jesse_Chen
2026-10-28 13:47:30 +08:00
co-authored by Claude Opus 5.5
parent cd6ad9d27a
commit a614895a2b
5 changed files with 42 additions and 1 deletions
+4
View File
@@ -2543,6 +2543,10 @@ def _load_local_module(module_name):
loaded = sys.modules.get(loaded_name)
loaded_file = getattr(loaded, '__file__', None)
if loaded_file and os.path.realpath(loaded_file) == os.path.realpath(module_path):
# import_module waits on the module lock while another thread is
# still executing it; sys.modules alone hands out a half-built
# module (gate run 5888, BUG-1482 reopened).
loaded = importlib.import_module(loaded_name)
_LOCAL_MODULE_CACHE[module_name] = loaded
return loaded
if os.path.isfile(module_path) and SCRIPTS_DIR in sys.path: