Re: Is there any way to unimport a library

2011-11-23 Thread DevPlayer
Seems so far the common way to fully unload any import is to exit the Python session. Only if this is true do I offer this hackish idea: Therefore you might wish to run an os script instead of a python script right off. Here is my hack at it... Something like this: file myapp.bat --

Re: Is there any way to unimport a library

2011-11-23 Thread DevPlayer
btw if you like processing text outside of python (say using grep or something) python -c help('modules') all_imports.log which you might note on windows get's processed to: python -c help('modules') 1 all_imports.log on windows from within a batch file --

Re: Is there any way to unimport a library

2011-11-21 Thread Jean-Michel Pichavant
Gelonida N wrote: I wondered whether there is any way to un-import a library, such, that it's occupied memory and the related shared libraries are released. My usecase is following: success = False try: import lib1_version1 as lib1 import lib2_version1 as lib2 success = True

Re: Is there any way to unimport a library

2011-11-21 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: Gelonida N wrote: I wondered whether there is any way to un-import a library, such, that it's occupied memory and the related shared libraries are released. My usecase is following: success = False try: import lib1_version1 as lib1 import lib2_version1

Re: Is there any way to unimport a library

2011-11-21 Thread DevPlayer
On Nov 20, 12:21 pm, Gelonida N gelon...@gmail.com wrote: I forgot to mention, that this is at the moment more a thought experiment, than a real need. At the moment I will do exactly what you suggested. I will make sure, that always the first import fails. But I wanted to learn more what is

Is there any way to unimport a library

2011-11-20 Thread Gelonida N
I wondered whether there is any way to un-import a library, such, that it's occupied memory and the related shared libraries are released. My usecase is following: success = False try: import lib1_version1 as lib1 import lib2_version1 as lib2 success = True except ImportError:

Re: Is there any way to unimport a library

2011-11-20 Thread Miki Tebeka
del sys.modules['my-module'] However if your module imported other modules, they'll still be there. If there are references to objects your module created, they'll still be there. A better option IMO is to use imp.find_module and then import. --

Re: Is there any way to unimport a library

2011-11-20 Thread Steven D'Aprano
On Sun, 20 Nov 2011 16:15:05 +0100, Gelonida N wrote: I wondered whether there is any way to un-import a library, such, that it's occupied memory and the related shared libraries are released. Not really. Python modules are objects, like everything else in Python, and can only be deleted

Re: Is there any way to unimport a library

2011-11-20 Thread Gelonida N
Steven, Mika, Thanks for your answers. It's always good to know which options exist. It makes it easier to choose the right one depending on the situation. On 11/20/2011 04:46 PM, Steven D'Aprano wrote: On Sun, 20 Nov 2011 16:15:05 +0100, Gelonida N wrote: I wondered whether there is any

Re: Is there any way to unimport a library

2011-11-20 Thread Chris Angelico
On Mon, Nov 21, 2011 at 3:39 AM, Gelonida N gelon...@gmail.com wrote: No mixing would not be possible. So either I need the first two libs or the second two. I wonder, can you make the first one import the second one? That automatically defines your dependency right there, and may make things

Re: Is there any way to unimport a library

2011-11-20 Thread Gelonida N
I forgot to mention, that this is at the moment more a thought experiment, than a real need. On 11/20/2011 05:53 PM, Chris Angelico wrote: On Mon, Nov 21, 2011 at 3:39 AM, Gelonida N gelon...@gmail.com wrote: No mixing would not be possible. So either I need the first two libs or the second

Re: Is there any way to unimport a library

2011-11-20 Thread alex23
On Nov 21, 1:15 am, Gelonida N gelon...@gmail.com wrote: I wondered whether there is any way to un-import a library, such, that it's occupied  memory and the related shared libraries are released. My usecase is following: success = False try:     import lib1_version1 as lib1     import