Skip to content

Commit cf89be2

Browse files
Added functions to print imported Python modules and/or loaded shared C/C++ libraries
1 parent 0f8fe2a commit cf89be2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
3+
def print_python_imported_modules():
4+
# print imported Python modules with their paths
5+
print(" ===== imported Python modules =====")
6+
for module_name, module in sorted(sys.modules.items()):
7+
try:
8+
module_file = module.__file__
9+
if module_file:
10+
print(f"{module_name}: {module_file}")
11+
except AttributeError:
12+
pass
13+
14+
def print_loaded_shared_libraries():
15+
# print loaded shared libraries from /proc/self/maps
16+
print(" ===== loaded shared C/C++ libraries =====")
17+
with open("/proc/self/maps", "r") as maps_file:
18+
lines = maps_file.readlines()
19+
for line in lines:
20+
if ".so" in line:
21+
parts = line.split()
22+
if len(parts) > 5:
23+
print(parts[5])
24+
25+
if __name__ == "__main__":
26+
# import numpy
27+
# import pandas
28+
29+
print("")
30+
print_python_imported_modules()
31+
print("")
32+
print_loaded_shared_libraries()
33+
print("")

0 commit comments

Comments
 (0)