I have the following code
import ctypes
lib1 = ctypes.cdll.LoadLibrary(\"./mylib.so\")
# modify mylib.so (code generation and compilation) or even delete it
Simplifying CristiFatis answer a bit, I wrote a close-library function. The following code can be used to develop in your shared library and call it (in the most recent version) from python.
import ctypes
def ctypesCloseLibrary(lib):
dlclose_func = ctypes.CDLL(None).dlclose
dlclose_func.argtypes = [ctypes.c_void_p]
dlclose_func.restype = ctypes.c_int
dlclose_func(lib._handle)
if __name__== "__main__":
lib = ctypes.cdll.LoadLibrary('./mylib.so')
# do things with lib_MyClass
ctypesCloseLibrary(lib)
Just call ctypesCloseLibrary
when you want lib
to be reloadable by lib = ctypes.cdll.LoadLibrary('./mylib.so')
.