Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson
> On Nov 24, 2014, at 2:44 AM, Ned Batchelder wrote: > > 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

Re: unloading a module created with imp.new_module

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 5:48 PM, Patrick Stinson wrote: > Is it still possible to import non-module objects? I guess this question is > just for fun now :) rosuav@sikorsky:~$ python3 Python 3.5.0a0 (default:23ab1197df0b, Nov 20 2014, 12:57:44) [GCC 4.7.2] on linux Type "help", "copyright", "credi

Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson
> On Nov 24, 2014, at 6:12 AM, Ian Kelly wrote: > > > On Nov 24, 2014 1:27 AM, "Patrick Stinson" > wrote: > > > > How does the __del__ method have a reference to the module’s globals dict? > > because it references the print function? > > The module's dict becom

Re: unloading a module created with imp.new_module

2014-11-24 Thread Chris Angelico
On Tue, Nov 25, 2014 at 2:12 AM, Ian Kelly wrote: >> Crazy. Is there any other way to comfort when a module is being deleted >> beside defining a class object with a printing dtor? > > Modules don't strictly have to be ModuleType. You could substitute a class > with a __del__ method for the module

Re: unloading a module created with imp.new_module

2014-11-24 Thread Ian Kelly
On Nov 24, 2014 1:27 AM, "Patrick Stinson" wrote: > > How does the __del__ method have a reference to the module’s globals dict? because it references the print function? The module's dict becomes the __globals__ dict used by the function for looking up globals and builtins. > Crazy. Is there an

Re: unloading a module created with imp.new_module

2014-11-24 Thread Chris Angelico
On Mon, Nov 24, 2014 at 10:21 PM, Ned Batchelder wrote: > Keep in mind that Python object have a reference to their class. If your > users are defining classes in their modules, and you instantiate the class > to create objects, then even when you reload updated code, the old objects > will still

Re: unloading a module created with imp.new_module

2014-11-24 Thread Ned Batchelder
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)

Re: unloading a module created with imp.new_module

2014-11-24 Thread Ned Batchelder
On 11/24/14 2:25 AM, Patrick Stinson wrote: Basically, I have an app and am making it possible for the users to automate it by writing python scripts that run against the app's API. It includes PyQt5 widgets, a QScintilla editor, and a simple API for I/O. Apple’s app store is the plan. Right now

Re: unloading a module created with imp.new_module

2014-11-24 Thread Chris Angelico
On Mon, Nov 24, 2014 at 6:27 PM, Patrick Stinson wrote: > How does the __del__ method have a reference to the module’s globals dict? > because it references the print function? > > Crazy. Is there any other way to comfort when a module is being deleted > beside defining a class object with a print

Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson
How does the __del__ method have a reference to the module’s globals dict? because it references the print function? Crazy. Is there any other way to comfort when a module is being deleted beside defining a class object with a printing dtor? > On Nov 23, 2014, at 4:27 PM, Ian Kelly wrote: >

Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson
Basically, I have an app and am making it possible for the users to automate it by writing python scripts that run against the app's API. It includes PyQt5 widgets, a QScintilla editor, and a simple API for I/O. Apple’s app store is the plan. Right now I create a new module with types.ModuleTyp

Re: unloading a module created with imp.new_module

2014-11-24 Thread Patrick Stinson
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 sys import types import time import gc s = """

Re: unloading a module created with imp.new_module

2014-11-23 Thread Steven D'Aprano
On Sat, 22 Nov 2014 21:49:32 -0900, Patrick Stinson wrote: > If I create a module with imp.new_module(name), how can I unload it so > that all the references contained in it are set to zero and the module > is deleted? deleting the reference that is returned doesn’t seem to do > the job, and it’s

Re: unloading a module created with imp.new_module

2014-11-23 Thread Ned Batchelder
On 11/23/14 1:49 AM, Patrick Stinson wrote: If I create a module with imp.new_module(name), how can I unload it so that all the references contained in it are set to zero and the module is deleted? deleting the reference that is returned doesn’t seem to do the job, and it’s not in sys.modules,

Re: unloading a module created with imp.new_module

2014-11-23 Thread Ian Kelly
On Nov 23, 2014 4:10 AM, "Patrick Stinson" wrote: > 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 th

Re: unloading a module created with imp.new_module

2014-11-23 Thread Ian Kelly
On Sun, Nov 23, 2014 at 2:48 AM, Ian Kelly wrote: > On Sat, Nov 22, 2014 at 11:49 PM, Patrick Stinson > wrote: >> If I create a module with imp.new_module(name), how can I unload it so that >> all the references contained in it are set to zero and the module is >> deleted? deleting the referen

Re: unloading a module created with imp.new_module

2014-11-23 Thread Ian Kelly
On Sat, Nov 22, 2014 at 11:49 PM, Patrick Stinson wrote: > If I create a module with imp.new_module(name), how can I unload it so that > all the references contained in it are set to zero and the module is deleted? > deleting the reference that is returned doesn’t seem to do the job, and it’s >

Re: Unloading a module

2009-10-22 Thread Gabriel Genellina
En Thu, 22 Oct 2009 11:59:58 -0300, lallous escribió: If a reference to an imported module reaches zero will Python cleanup everything related to that module and unload the compiled code, etc, etc...? The module object itself (as any other object whose reference count reaches zero) will be