From: Dave Guthrie on
I am creating an application which has it's code split between python
and C. The Python is used to provide a high level GUI interface and
the C is for low level functions. I use SWIG to create Python Bindings
for the C functions. I want to implement a feature where there is a
button in the toolbar of the GUI which will automatically compile the
C code into a .pyd file. The problem I have is when the GUI is
running, the .pyd is loaded as a DLL and thus is locked by the GUI, so
I can't get "gcc" to overwrite the .pyd file.

I have tried to force the GUI to close it's handle on the file

handle =
ctypes.windll.kernel32.GetModuleHandleA("_FirmwareSubSys.pyd")

if handle == 0:
print "_FirmwareSubSys.pyd not loaded"
else:
_ctypes.FreeLibrary(handle)

But by doing this the next time I load the DLL python crashes.

Do anyone know how to dynamically compile and load SWIG Python
Bindings?