Unimporting a module
Christian Tismer
tismer at appliedbiometrics.com
Thu May 13 13:09:23 EDT 1999
Taylor Anderson wrote:
>
> I am using the C-extension capabilities of Python, and am developing
> DLLs that I am loading in as modules in Python. My problem: after I
> have imported a module into Python, I cannot rebuild it in VC without
> the linker telling me that it cannot access the DLL. My question: how
> can I "unimport" the module so that my linker can write to the DLL
> (.pyd) file? As it stands now, I have to quit the Python IDE, link, and
> get back into Python.
If you know what you are doing, you can throw out a dll again.
First of all, you must make absolutely absolutely
sure to get rid of all references to the module.
Every reference must go away, or you are about to crash.
Here an example:
(tried this with a .pyd named "herz.pyd")
import sys
import herz
del sys.modules["herz"]
print sys.getrefcount(herz) # must be 2 to be safe!
del herz # but also del all refs to its internals!
import win32api
handle = win32api.LoadLibrary("herz.pyd")
win32api.FreeLibrary(handle) # undo this one
win32api.FreeLibrary(handle) # and the internal one :-)
happy core dumping - chris
--
Christian Tismer :^) <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home
More information about the Python-list
mailing list