def _load_preload_lib():
"""profiling won't work if the library isn't preloaded using LD_PRELOAD,
but we ensure it's loaded anyway so that we can import the cython
extension and call its functions still - otherwise it won't import since
it has not been linked to the preload library."""
import os
import ctypes
from distutils.sysconfig import get_config_var
this_dir = os.path.dirname(os.path.realpath(__file__))
so_name = os.path.join(this_dir, 'preload')
ext_suffix = get_config_var('EXT_SUFFIX')
if ext_suffix is not None:
so_name += ext_suffix
else:
so_name += '.so'
import sys
ctypes.CDLL(so_name, ctypes.RTLD_GLOBAL)
return so_name
python类RTLD_GLOBAL的实例源码
def openLibrary():
import ctypes
import ctypes.util
try:
if sys.platform.startswith("win"):
dll_path = "src/lib/opensslVerify/libeay32.dll"
elif sys.platform == "cygwin":
dll_path = "/bin/cygcrypto-1.0.0.dll"
else:
dll_path = "/usr/local/ssl/lib/libcrypto.so"
ssl = ctypes.CDLL(dll_path, ctypes.RTLD_GLOBAL)
assert ssl
except:
dll_path = ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto')
ssl = ctypes.CDLL(dll_path or 'libeay32', ctypes.RTLD_GLOBAL)
return ssl
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def COINMP_DLL_load_dll(path):
"""
function that loads the DLL useful for debugging installation problems
"""
import ctypes
if os.name == 'nt':
lib = ctypes.windll.LoadLibrary(str(path[-1]))
else:
#linux hack to get working
mode = ctypes.RTLD_GLOBAL
for libpath in path[:-1]:
#RTLD_LAZY = 0x00001
ctypes.CDLL(libpath, mode = mode)
lib = ctypes.CDLL(path[-1], mode = mode)
return lib
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def _load_lib():
"""Load libary in build/lib."""
lib_root = Path(__file__).parents[2]
lib_path = os.path.join(lib_root, 'cuda/build/lib/')
path_to_so_file = os.path.join(lib_path, "libc_runtime_api.so")
lib = ctypes.CDLL(path_to_so_file, ctypes.RTLD_GLOBAL)
return lib
# global library instance
backend_ctypes.py 文件源码
项目:aws-lambda-python-codecommit-s3-deliver
作者: 0xlen
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def use_mkl():
set_compiler(
cmd = 'ifort',
prefix = '',
infix = '_mp_',
suffix = '_',
debug = """
-g
-traceback
-gen-interfaces
-warn all
-check all
-fpe0
-ftrapuv
-I/opt/intel/mkl/include
""",
release = """
-fast
-I/opt/intel/mkl/include
""",
link = """
-L/opt/intel/mkl/lib/intel64
-lmkl_intel_lp64
-lmkl_core
-lmkl_sequential
-lpthread
-lm
""",
error_regex = '(error #|ld:)',
warning_regex = '(warning #|remark #)',
)
# needed to load mkl
# see: https://answers.launchpad.net/dolfin/+question/205219
import ctypes
ctypes.CDLL('libmkl_rt.so', ctypes.RTLD_GLOBAL)
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def __init__(self):
self.RTLD_LAZY = 0 # not supported anyway by ctypes
self.RTLD_NOW = 0
self.RTLD_GLOBAL = ctypes.RTLD_GLOBAL
self.RTLD_LOCAL = ctypes.RTLD_LOCAL
def _lazy_init_libgfapi():
"""
Loads ctypes library only if not loaded already
"""
global _api
if not _api:
_api = ctypes.CDLL(find_library("gfapi"), ctypes.RTLD_GLOBAL)
def load( lib, so_version = None, path = None, so_ext = None):
"""Thin wrapper around the ctypes.CDLL function for loading shared
library.
If the path argument is non Null the function will first try to
load with full path. If that fails it wil also try to load without
a path component, invoking normal dlopen() semantics.
"""
dll = None
lib_files = [ lib_name( lib, path = None, so_version = so_version ),
lib_name( lib, path = None, so_version = so_version, so_ext = so_ext ),
lib_name( lib, path = path, so_version = so_version ),
lib_name( lib, path = path, so_version = so_version, so_ext = so_ext )
]
for lib_file in lib_files:
try:
dll = ctypes.CDLL(lib_file , ctypes.RTLD_GLOBAL)
return dll
except Exception as exc:
error = exc
error_msg = "\nFailed to load shared library:%s\n\ndlopen() error: %s\n" % (lib , error)
LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH")
if not LD_LIBRARY_PATH:
LD_LIBRARY_PATH = ""
error_msg += """
The runtime linker has searched through the default location of shared
libraries, and also the locations mentioned in your LD_LIBRARY_PATH
variable. Your current LD_LIBRARY_PATH setting is:
LD_LIBRARY_PATH: %s
You might need to update this variable?
""" % LD_LIBRARY_PATH
raise ImportError(error_msg)
def use_mkl_blas_lapack():
set_compiler(
cmd = 'ifort',
prefix = '',
infix = '_mp_',
suffix = '_',
debug = """
-g
-traceback
-gen-interfaces
-warn all
-check all
-fpe0
-ftrapuv
-qopenmp
-I/opt/intel/mkl/include/intel64/lp64
-I/opt/intel/mkl/include
""",
release = """
-fast
-qopenmp
-I/opt/intel/mkl/include/intel64/lp64
-I/opt/intel/mkl/include
""",
link = """
/opt/intel/mkl/lib/intel64/libmkl_blas95_lp64.a
/opt/intel/mkl/lib/intel64/libmkl_lapack95_lp64.a
-L/opt/intel/mkl/lib/intel64
-lmkl_intel_lp64
-lmkl_core
-lmkl_intel_thread
-lpthread
-lm
-ldl
""",
error_regex = '(error #|ld:)',
warning_regex = '(warning #|remark #)',
)
# needed to load mkl
# see: https://answers.launchpad.net/dolfin/+question/205219
import ctypes
ctypes.CDLL('libmkl_rt.so', ctypes.RTLD_GLOBAL)
ctypes.CDLL('/opt/intel/lib/intel64/libiomp5.so', ctypes.RTLD_GLOBAL)