dynamic import of dynamically created modules failes

Peter Otten __peter__ at web.de
Tue Mar 31 14:42:58 EDT 2020


Dieter Maurer wrote:

> Stephan Lukits wrote at 2020-3-31 17:44 +0300:
>>background:
>>
>>- a daemon creates package p1 (e.g. directory with __init__.py-file) and
>>in p1 a module m1 is created.
>>
>>- Then the daemon wants to import from m1, which functions (so far all
>>the time).
>>
>>- Then a module m2 is created in p1 and the daemon wants to import from
>>m2 which fails (most of the time but *not* always) with
>>ModuleNotFoundError.
>>
>>See the little test script at the end which reproduces the problem.
>> ...
> 
> I remember a similar report (some time ago). There, caching has
> been responsible. I have forgotten how to invalidate the caches.
> But, you could try logic found in
> `importlib._bootstrap_external.PathFinder.invalidate_caches`.

[brainstorm mode]

Do namespace packages cache as aggressively? Maybe it would help to omit 
p1/__init__.py.



More information about the Python-list mailing list