dynamic import of dynamically created modules failes

Dieter Maurer dieter at handshake.de
Tue Mar 31 13:00:07 EDT 2020


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`.


More information about the Python-list mailing list