Last active
March 10, 2024 01:32
-
-
Save TheWaWaR/d3c630f72dd631a0f336 to your computer and use it in GitHub Desktop.
Python reload shared library test script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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