[Solved] Re: dynamic import of dynamically created modules failes
Stephan Lukits
stephan.lukits at gmail.com
Tue Mar 31 14:39:14 EDT 2020
On 3/31/20 8:00 PM, 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`.
Yes, removing the entry for p1 from 'sys.path_importer_cache' seems to
solve the problem.
Thank you.
More information about the Python-list
mailing list