Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81452

Re: unloading a module created with imp.new_module

From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: unloading a module created with imp.new_module
Date 2014-11-24 06:44 -0500
References <C093BC09-3AB7-49DB-B160-265A34C6BCDA@gmail.com> <CALwzidnHV8smFHtvixtdhX-i94PWbwNKSRrR6HAfhn2HOKqxsw@mail.gmail.com> <CALwzid=9Zgu3svDP-mv8-1DrZkKkDcNTxy+D=obwGsOGzB5aZQ@mail.gmail.com> <B8391E6B-5AA4-4125-96BC-74B12B46E927@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16246.1416829460.18130.python-list@python.org> (permalink)

Show all headers | View raw


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
> importsys
> import types
> importtime
> importgc
>
> s= """
> class A:
>      def __del__(self):
>          print('__del__')
> a = A()
> """
>
> m = types.ModuleType('mine')
> exec(s, m.__dict__)
> print('deleting...')
> m= None
> print('done')
>
> and the output is:
>
> deleting...
> done
> __del__
>
> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: unloading a module created with imp.new_module Ned Batchelder <ned@nedbatchelder.com> - 2014-11-24 06:44 -0500

csiph-web