Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81452 > unrolled thread
| Started by | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| First post | 2014-11-24 06:44 -0500 |
| Last post | 2014-11-24 06:44 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: unloading a module created with imp.new_module Ned Batchelder <ned@nedbatchelder.com> - 2014-11-24 06:44 -0500
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-11-24 06:44 -0500 |
| Subject | Re: unloading a module created with imp.new_module |
| Message-ID | <mailman.16246.1416829460.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web