當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。