Tuesday, June 30, 2009

How to unload a python extension dll

I haven't found the answer. But I would like to put here
as a place holder. Also hoping if an expert can comment
on it. :)

Basically, the problem is: I have a python extension
written in C/C++. As a python module, I import it
in my interactive shell (IPython indeed). I modified
the C/C++ code, rebuild the extension, and want to
test it out in my python shell. But even I deleted the
module from the interactive shell namespace, the python
process is still holding a handle to the DLL (pyd). I
have to kill the python process and restart the testing
from beginning again. It will be nice if I can ask python
VM to release the handle of the pyd module and re-import
the module again.

Can I do it?

1 comment:

  1. Hi,
    on Windows & Python 2.6.2 the following works


    from ctypes import *

    # load dll
    lib = cdll.LoadLibrary('mylib.dll')

    # then to release dll
    windll.kernel32.FreeLibrary(lib._handle)

    ReplyDelete