本文整理汇总了Python中ctypes.CDLL属性的典型用法代码示例。如果您正苦于以下问题:Python ctypes.CDLL属性的具体用法?Python ctypes.CDLL怎么用?Python ctypes.CDLL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ctypes
的用法示例。
在下文中一共展示了ctypes.CDLL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _setup_cuda_object
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def _setup_cuda_object():
global _CUDA_OBJECT
global _HAS_CUDA
libnames = ('libcuda.so', 'libcuda.dylib', 'nvcuda.dll')
for libname in libnames:
try:
cuda = ctypes.CDLL(libname)
if cuda.cuInit(0) == _CUDA_SUCCESS:
_CUDA_OBJECT = cuda
_HAS_CUDA = True
else:
_CUDA_OBJECT = None
_HAS_CUDA = False
except OSError:
continue
else:
break
else:
_CUDA_OBJECT = None
_HAS_CUDA = False
示例2: load_library
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def load_library(libname):
# numpy 1.6 has bug in ctypeslib.load_library, see numpy/distutils/misc_util.py
if '1.6' in numpy.__version__:
if (sys.platform.startswith('linux') or
sys.platform.startswith('gnukfreebsd')):
so_ext = '.so'
elif sys.platform.startswith('darwin'):
so_ext = '.dylib'
elif sys.platform.startswith('win'):
so_ext = '.dll'
else:
raise OSError('Unknown platform')
libname_so = libname + so_ext
return ctypes.CDLL(os.path.join(os.path.dirname(__file__), libname_so))
else:
_loaderpath = os.path.dirname(__file__)
return numpy.ctypeslib.load_library(libname, _loaderpath)
#Fixme, the standard resouce module gives wrong number when objects are released
#see http://fa.bianp.net/blog/2013/different-ways-to-get-memory-consumption-or-lessons-learned-from-memory_profiler/#fn:1
#or use slow functions as memory_profiler._get_memory did
示例3: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def __init__(self):
dir_path = os.path.dirname(os.path.realpath(__file__))
self.lib = ctypes.CDLL('%s/build/dll/libmol.so' % dir_path)
# self.lib.Smiles2Graph.restype = ctypes.c_void_p
self.lib.PrepareBatchFeature.restype = ctypes.c_int
self.lib.DumpFeatures.restype = ctypes.c_int
self.lib.LoadMolGraph.restype = ctypes.c_int
self.lib.NodeFeatDim.restype = ctypes.c_int
self.lib.EdgeFeatDim.restype = ctypes.c_int
self.lib.NumNodes.restype = ctypes.c_int
self.lib.NumEdges.restype = ctypes.c_int
self.lib.EdgeList.restype = ctypes.c_void_p
self.num_node_feats = self.lib.NodeFeatDim()
self.num_edge_feats = self.lib.EdgeFeatDim()
示例4: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def __init__(self, args):
dir_path = os.path.dirname(os.path.realpath(__file__))
self.lib = ctypes.CDLL('%s/build/dll/libs2v.so' % dir_path)
self.lib.GetGraphStruct.restype = ctypes.c_void_p
self.lib.PrepareBatchGraph.restype = ctypes.c_int
self.lib.PrepareMeanField.restype = ctypes.c_int
self.lib.PrepareLoopyBP.restype = ctypes.c_int
self.lib.NumEdgePairs.restype = ctypes.c_int
if sys.version_info[0] > 2:
args = [arg.encode() for arg in args] # str -> bytes for each element in args
arr = (ctypes.c_char_p * len(args))()
arr[:] = args
self.lib.Init(len(args), arr)
self.batch_graph_handle = ctypes.c_void_p(self.lib.GetGraphStruct())
示例5: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def __init__(self, ticket_number_key, request_data_key,
libcrypto_path=None):
self.check_des_key(ticket_number_key)
self.check_des_key(request_data_key)
self.ticket_number_key = ticket_number_key
self.request_data_key = request_data_key
if not libcrypto_path:
from ctypes.util import find_library
libcrypto_path = find_library('crypto')
if not libcrypto_path:
raise Exception('libcrypto(OpenSSL) not found')
self.libcrypto = ctypes.CDLL(libcrypto_path)
if hasattr(self.libcrypto, 'OpenSSL_add_all_ciphers'):
self.libcrypto.OpenSSL_add_all_ciphers()
示例6: mkl_get_nthreads
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def mkl_get_nthreads():
"""wrapper around MKL ``get_max_threads``.
Returns
-------
max_threads : int
The maximum number of threads used by MKL. ``-1`` if unable to read out.
"""
try:
import mkl # available in conda MKL
return mkl.get_max_threads()
except ImportError:
try:
mkl_rt = ctypes.CDLL('libmkl_rt.so')
return mkl_rt.mkl_get_max_threads()
except OSError:
warnings.warn("MKL library not found: can't get nthreads")
return -1
示例7: mkl_set_nthreads
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def mkl_set_nthreads(n):
"""wrapper around MKL ``set_num_threads``.
Parameters
----------
n : int
the number of threads to use
Returns
-------
success : bool
whether the shared library was found and set.
"""
try:
import mkl # available in conda MKL
mkl.set_num_threads(n)
return True
except ImportError:
try:
mkl_rt = ctypes.CDLL('libmkl_rt.so')
mkl_rt.mkl_set_num_threads(ctypes.byref(ctypes.c_int(n)))
return True
except OSError:
warnings.warn("MKL library not found: can't set nthreads")
return False
示例8: _load_lapack
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def _load_lapack(libs=[
"libLAPACK.dylib", "libmkl_rt.so", "libmkl_intel_lp64.so", "liblapack.so",
"libopenblas.dll",
find_library('lapack')
],
warn=True):
"""load & return a CLAPACK library."""
global _lapack_lib
if _lapack_lib is None:
for l in libs:
if l is None:
continue
try:
_lapack_lib = CDLL(l)
_set_CLAPACK_callsignatures(_lapack_lib)
if warn:
warnings.warn("[Loaded " + l + " for gesvd]")
break
except OSError:
pass
if _lapack_lib is None:
msg = "Couldn't find LAPACK library for 'gesvd' workaround.\nTried: " + str(libs)
raise EnvironmentError(msg)
warnings.warn("Old Scipy version. We will drop the support!", FutureWarning)
return _lapack_lib
示例9: monotonicInit
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def monotonicInit(self):
try:
from RMOSGlue.rmOSPlatform import RMOSPlatform
if RMOSPlatform().AUTODETECTED == RMOSPlatform.ANDROID:
librt = ctypes.CDLL('libc.so', use_errno=True)
log.info("Initialised Android monotonic clock")
elif RMOSPlatform().AUTODETECTED == RMOSPlatform.OPENWRT:
librt = ctypes.CDLL('librt.so.0', use_errno=True)
log.info("Initialised OpenWRT monotonic clock")
else:
librt = ctypes.CDLL('librt.so.1', use_errno=True)
log.info("Initialised generic monotonic clock")
self.clock_gettime = librt.clock_gettime
self.clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
self.get = self.monotonicTime
except Exception, e:
self.get = self.monotonicFallback
log.error("Cannot initialise monotonicClock will use fallback time.time() method !")
示例10: _set_proc_title
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def _set_proc_title(process_name: str) -> None:
"""
BSD specific calls (should be compataible with both FreeBSD and OpenBSD:
http://fxr.watson.org/fxr/source/gen/setproctitle.c?v=FREEBSD-LIBC
http://www.rootr.net/man/man/setproctitle/3
"""
libc = ctypes.CDLL(ctypes.util.find_library('c'))
name_buffer = ctypes.create_string_buffer(len(process_name) + 1)
name_buffer.value = process_name.encode()
try:
libc.setproctitle(ctypes.byref(name_buffer))
except AttributeError:
# Possible issue (seen on OSX):
# AttributeError: dlsym(0x7fff6a41d1e0, setproctitle): symbol not found
pass
示例11: get_os_tid
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def get_os_tid():
"""
Get the Linux process id associated with the current thread
Returns:
int: The process id
"""
if sys.platform.startswith(u'linux'):
return ctypes.CDLL(u'libc.so.6').syscall(186)
else:
# TODO: This is hacky - we need to replace it with something that actually returns the OS thread ID
if is_python_2():
return threading._get_ident()
else:
return threading.get_ident()
示例12: _setup_environment
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def _setup_environment(environ):
# Cygwin requires some special voodoo to set the environment variables
# properly so that Oracle will see them.
if platform.system().upper().startswith('CYGWIN'):
try:
import ctypes
except ImportError as e:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured("Error loading ctypes: %s; "
"the Oracle backend requires ctypes to "
"operate correctly under Cygwin." % e)
kernel32 = ctypes.CDLL('kernel32')
for name, value in environ:
kernel32.SetEnvironmentVariableA(name, value)
else:
os.environ.update(environ)
示例13: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def __init__(self, args):
dir_path = os.path.dirname(os.path.realpath(__file__))
self.lib = ctypes.CDLL('%s/build/dll/libgnn.so' % dir_path)
self.lib.GetGraphStruct.restype = ctypes.c_void_p
self.lib.PrepareBatchGraph.restype = ctypes.c_int
self.lib.PrepareSparseMatrices.restype = ctypes.c_int
self.lib.NumEdgePairs.restype = ctypes.c_int
if sys.version_info[0] > 2:
args = [arg.encode() for arg in args] # str -> bytes for each element in args
arr = (ctypes.c_char_p * len(args))()
arr[:] = args
self.lib.Init(len(args), arr)
self.batch_graph_handle = ctypes.c_void_p(self.lib.GetGraphStruct())
示例14: have_compatible_glibc
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def have_compatible_glibc(major, minimum_minor):
# ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
# manpage says, "If filename is NULL, then the returned handle is for the
# main program". This way we can let the linker do the work to figure out
# which libc our process is actually using.
process_namespace = ctypes.CDLL(None)
try:
gnu_get_libc_version = process_namespace.gnu_get_libc_version
except AttributeError:
# Symbol doesn't exist -> therefore, we are not linked to
# glibc.
return False
# Call gnu_get_libc_version, which returns a string like "2.5".
gnu_get_libc_version.restype = ctypes.c_char_p
version_str = gnu_get_libc_version()
# py2 / py3 compatibility:
if not isinstance(version_str, str):
version_str = version_str.decode("ascii")
return check_glibc_version(version_str, major, minimum_minor)
示例15: copyload_shared_lib
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import CDLL [as 别名]
def copyload_shared_lib(dst_prefix=TESTFILE_PREFIX):
"""Ctx manager which picks up a random shared CO lib used
by this process, copies it in another location and loads it
in memory via ctypes. Return the new absolutized path.
"""
ext = ".so"
dst = tempfile.mktemp(prefix=dst_prefix, suffix=ext)
libs = [x.path for x in psutil.Process().memory_maps() if
os.path.splitext(x.path)[1] == ext and
'python' in x.path.lower()]
src = random.choice(libs)
shutil.copyfile(src, dst)
try:
ctypes.CDLL(dst)
yield dst
finally:
safe_rmpath(dst)