April 17, 2021
2:34 p.m.
On Wed, 14 Apr 2021, 9:03 am Kun He, <hekun19890913@gmail.com> wrote:
I'm afraid that I misunderstood your previous mail. When you said " it was basically not possible to unload a C extension.", it means that we can't delete the module from sys.modules (del sys.modules['_abc'])?
Extension modules that use the legacy initialisation API have a hidden copy of their top level namespace created.
If you delete them from sys.modules, reimporting them will create a new module object, but it won't recreate the *contents* of the module - those will be taken from the hidden copy rather than executing the module initialisation again.
Only extension modules that use the newer multi-phase initialisation API can be truly unloaded and reloaded.
Cheers, Nick.