Skip to content

Instantly share code, notes, and snippets.

@TheWaWaR
Last active March 10, 2024 01:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TheWaWaR/d3c630f72dd631a0f336 to your computer and use it in GitHub Desktop.
Save TheWaWaR/d3c630f72dd631a0f336 to your computer and use it in GitHub Desktop.
Python reload shared library test script
#!/usr/bin/env python
#coding: utf-8
import os
import sys
import ctypes
def is_loaded(lib):
libp = os.path.abspath(lib)
ret = os.system("lsof -p %d | grep %s > /dev/null" % (os.getpid(), libp))
return (ret == 0)
def reload_lib(lib):
handle = lib._handle
name = lib._name
del lib
while is_loaded(name):
libdl = ctypes.CDLL("libdl.so")
libdl.dlclose(handle)
return ctypes.cdll.LoadLibrary(name)
def main():
libpath = sys.argv[1]
lib = ctypes.cdll.LoadLibrary(libpath)
lib.process()
raw_input("Rebuilding library....., When you are done, press [ENTER]:")
lib = reload_lib(lib)
lib.process()
print 'DONE'
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment