当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.CDLL属性代码示例

本文整理汇总了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 
开发者ID:mme,项目名称:vergeml,代码行数:23,代码来源:libraries.py

示例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 
开发者ID:pyscf,项目名称:pyscf,代码行数:23,代码来源:misc.py

示例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() 
开发者ID:Hanjun-Dai,项目名称:pytorch_structure2vec,代码行数:19,代码来源:mol_lib.py

示例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()) 
开发者ID:Hanjun-Dai,项目名称:pytorch_structure2vec,代码行数:19,代码来源:s2v_lib.py

示例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() 
开发者ID:realityone,项目名称:libcet,代码行数:20,代码来源:cet.py

示例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 
开发者ID:tenpy,项目名称:tenpy,代码行数:20,代码来源:process.py

示例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 
开发者ID:tenpy,项目名称:tenpy,代码行数:27,代码来源:process.py

示例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 
开发者ID:tenpy,项目名称:tenpy,代码行数:27,代码来源:svd_robust.py

示例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 !") 
开发者ID:sprinkler,项目名称:rainmachine-developer-resources,代码行数:21,代码来源:rmTimeUtils.py

示例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 
开发者ID:torproject,项目名称:stem,代码行数:20,代码来源:system.py

示例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() 
开发者ID:yahoo,项目名称:panoptes,代码行数:18,代码来源:helpers.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:18,代码来源:base.py

示例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()) 
开发者ID:muhanzhang,项目名称:pytorch_DGCNN,代码行数:18,代码来源:gnn_lib.py

示例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) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:23,代码来源:pep425tags.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:__init__.py


注:本文中的ctypes.CDLL属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。