code_junkie

How can I unload a DLL using ctypes in Python?

Nov 12th, 2011
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. mydll = ctypes.CDLL('...')
  2. del mydll
  3. mydll = ctypes.CDLL('...')
  4.  
  5. mydll = ctypes.CDLL('./mylib.so')
  6. handle = mydll._handle
  7. del mydll
  8. while isLoaded('./mylib.so'):
  9. dlclose(handle)
  10.  
  11. def isLoaded(lib):
  12. libp = os.path.abspath(lib)
  13. ret = os.system("lsof -p %d | grep %s > /dev/null" % (os.getpid(), libp))
  14. return (ret == 0)
  15.  
  16. def dlclose(handle)
  17. libdl = ctypes.CDLL("libdl.so")
  18. libdl.dlclose(handle)
Add Comment
Please, Sign In to add comment