unloading a module created with imp.new_module
ned at nedbatchelder.com
Mon Nov 24 12:44:10 CET 2014
On 11/23/14 5:10 AM, Patrick Stinson wrote:
> I am defining a single class with a destructor method that prints
> ‘__del__’, and running that source code string using exec with the
> module’s dict like so:
> import rtmidi
> import types
> s= """
> class A:
> def __del__(self):
> a = A()
> m = types.ModuleType('mine')
> exec(s, m.__dict__)
> m= None
> and the output is:
> I the “__del__" to come between “deleting…” and “done”. This is not
> being run from the interactive interpreter by via a .py file.
Let's look at this another way: Why do you need the module to be
unloaded? Isn't it enough to have the new code loaded?
Ned Batchelder, http://nedbatchelder.com
More information about the Python-list