本文整理汇总了Python中ctypes.cdll.LoadLibrary方法的典型用法代码示例。如果您正苦于以下问题:Python cdll.LoadLibrary方法的具体用法?Python cdll.LoadLibrary怎么用?Python cdll.LoadLibrary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes.cdll
的用法示例。
在下文中一共展示了cdll.LoadLibrary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register_process_with_cgrulesengd
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def _register_process_with_cgrulesengd(pid):
"""Tell cgrulesengd daemon to not move the given process into other cgroups,
if libcgroup is available.
"""
# Logging/printing from inside preexec_fn would end up in the output file,
# not in the correct logger, thus it is disabled here.
from ctypes import cdll
try:
libcgroup = cdll.LoadLibrary("libcgroup.so.1")
failure = libcgroup.cgroup_init()
if failure:
pass
else:
CGROUP_DAEMON_UNCHANGE_CHILDREN = 0x1
failure = libcgroup.cgroup_register_unchanged_process(
pid, CGROUP_DAEMON_UNCHANGE_CHILDREN
)
if failure:
pass
# print('Could not register process to cgrulesndg, error {}. '
# 'Probably the daemon will mess up our cgroups.'.format(success))
except OSError:
pass
示例2: _load
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def _load(self):
library_path = find_library(self.name)
if library_path is None:
env_var_name = "PATH" if sys.platform == 'win32' else "LD_LIBRARY_PATH"
raise CannotFindPicoSDKError("PicoSDK (%s) not found, check %s" % (self.name, env_var_name))
try:
if sys.platform == 'win32':
from ctypes import WinDLL
result = WinDLL(library_path)
else:
from ctypes import cdll
result = cdll.LoadLibrary(library_path)
except OSError as e:
raise CannotOpenPicoSDKError("PicoSDK (%s) not compatible (check 32 vs 64-bit): %s" % (self.name, e))
return result
示例3: _get_pa_instance
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def _get_pa_instance():
# Suppress initial ALSA messages if using ALSA.
# Got this from: https://stackoverflow.com/a/17673011/12157649
try:
asound = cdll.LoadLibrary('libasound.so')
c_error_handler = ERROR_HANDLER_FUNC(
lambda filename, line, function, err, fmt: None
)
asound.snd_lib_error_set_handler(c_error_handler)
except:
# We'll most likely get here if the Port Audio host API isn't ALSA.
asound = None
# Create the pa instance.
pa = pyaudio.PyAudio()
# If necessary, restore the original error handler.
if asound:
asound.snd_lib_error_set_handler(None)
return pa
示例4: find_yajl_ctypes
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def find_yajl_ctypes(required):
'''
Finds and loads yajl shared object of the required major
version (1, 2, ...) using ctypes.
'''
# Importing ``ctypes`` should be in scope of this function to prevent failure
# of `backends`` package load in a runtime where ``ctypes`` is not available.
# Example of such environment is Google App Engine (GAE).
from ctypes import util, cdll
so_name = util.find_library('yajl')
if so_name is None:
raise YAJLImportError('YAJL shared object not found.')
yajl = cdll.LoadLibrary(so_name)
require_version(yajl.yajl_version(), required)
return yajl
示例5: set_procname
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def set_procname(p_sProcName):
from ctypes import cdll, byref, create_string_buffer
libc = cdll.LoadLibrary('libc.so.6') #Loading a 3rd party library C
buff = create_string_buffer(len(p_sProcName)+1) #Note: One larger than the name (man prctl says that)
buff.value = p_sProcName #Null terminated string as it should be
libc.prctl(15, byref(buff), 0, 0, 0) #Refer to "#define" of "/usr/include/linux/prctl.h" for the misterious value 16 & arg[3..5] are zero as the man page says.
示例6: check_so
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def check_so(soname):
"""
Verify that we do have the 'soname' lib present in the system, and that it
can be loaded.
"""
if len(get_available_gpus()) == 0:
return None
# Try to force load lib, this would fail if the lib is not there :)
try:
lib = cdll.LoadLibrary(soname)
print("INFO: Found so as", lib)
assert lib.__class__.__name__ == 'CDLL'
assert lib._name == soname
return True
except OSError as ex:
print("WARNING:", ex)
return False
示例7: run
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def run(self, *args):
""" Execute Halide code that was compiled before. """
# Output names that our halide compilation produces
function_name, function_name_c, output_lib = output_names(
self.func, self.generator_source, self.builddir)
# Run
args_ctype = convert_to_ctypes(args, function_name_c)
# Directly load the lib
launch = cdll.LoadLibrary(output_lib)
# Call
error = getattr(launch, function_name_c)(*args_ctype)
if error != 0:
print('Halide call to {0} returned {1}'.format(function_name_c, error), file=sys.stderr)
exit()
示例8: __init__
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def __init__(self, path="./libsimilarity/libsimilarity.so"):
super(SIMILARITYNative, self).__init__(True)
self._u = cdll.LoadLibrary( path )
self._u.compress.restype = c_uint
self._u.ncd.restype = c_int
self._u.ncs.restype = c_int
self._u.cmid.restype = c_int
self._u.entropy.restype = c_double
self._u.levenshtein.restype = c_uint
self._u.kolmogorov.restype = c_uint
self._u.bennett.restype = c_double
self._u.RDTSC.restype = c_double
self.__libsim_t = LIBSIMILARITY_T()
self.set_compress_type( ZLIB_COMPRESS )
示例9: _errno_location
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def _errno_location():
"""
Try to get errno integer from libc using __errno_location_sym function.
This function is specific to OS with "libc.so.6" and may fails for
thread-safe libc.
"""
from ctypes import cdll
try:
libc = cdll.LoadLibrary("libc.so.6")
except OSError:
# Unable to open libc dynamic library
return None
try:
__errno_location = libc.__errno_location_sym
except AttributeError:
# libc doesn't have __errno_location
return None
__errno_location.restype = POINTER(c_int)
return __errno_location()[0]
示例10: __init__
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def __init__(self):
if os.name == 'nt':
fhandle = c_void_p()
try:
self.dll = cdll.LoadLibrary("ilorest_chif.dll")
except:
self.dll = cdll.LoadLibrary("hprest_chif.dll")
self.dll.ChifInitialize(None)
self.dll.ChifCreate.argtypes = [c_void_p]
self.dll.ChifCreate.restype = c_uint32
try:
status = self.dll.ChifCreate(byref(fhandle))
if status != BlobReturnCodes.SUCCESS:
raise HpIloInitialError("Error %s occurred while trying " \
"to open a channel to iLO" % status)
self.fhandle = fhandle
self.dll.ChifSetRecvTimeout(self.fhandle, 30000)
except Exception, excp:
self.unload()
raise excp
示例11: _load_library
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def _load_library(lib_path):
dll = cdll.LoadLibrary(os.path.realpath(lib_path))
dll.tims_open.argtypes = [c_char_p, c_uint32]
dll.tims_open.restype = c_uint64
dll.tims_close.argtypes = [c_uint64]
dll.tims_close.restype = None
dll.tims_get_last_error_string.argtypes = [c_char_p, c_uint32]
dll.tims_get_last_error_string.restype = c_uint32
dll.tims_has_recalibrated_state.argtypes = [c_uint64]
dll.tims_has_recalibrated_state.restype = c_uint32
dll.tims_read_scans_v2.argtypes = [
c_uint64, c_int64, c_uint32, c_uint32, c_void_p, c_uint32]
dll.tims_read_scans_v2.restype = c_uint32
dll.tims_oneoverk0_to_ccs_for_mz.argtypes = [c_double, c_int32, c_double]
dll.tims_oneoverk0_to_ccs_for_mz.restype = c_double
dll.tims_ccs_to_oneoverk0_for_mz.argtypes = [c_double, c_int32, c_double]
dll.tims_ccs_to_oneoverk0_for_mz.restype = c_double
convfunc_argtypes = [c_uint64, c_int64, POINTER(
c_double), POINTER(c_double), c_uint32]
for fn in [dll.tims_index_to_mz, dll.tims_mz_to_index, dll.tims_scannum_to_oneoverk0,
dll.tims_oneoverk0_to_scannum, dll.tims_scannum_to_voltage, dll.tims_voltage_to_scannum]:
fn.argtypes = convfunc_argtypes
fn.restype = c_uint32
return dll
示例12: test
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def test():
from ctypes import cdll
if os.name == "nt":
print cdll.msvcrt
print cdll.load("msvcrt")
print find_library("msvcrt")
if os.name == "posix":
# find and load_version
print find_library("m")
print find_library("c")
print find_library("bz2")
# getattr
## print cdll.m
## print cdll.bz2
# load
if sys.platform == "darwin":
print cdll.LoadLibrary("libm.dylib")
print cdll.LoadLibrary("libcrypto.dylib")
print cdll.LoadLibrary("libSystem.dylib")
print cdll.LoadLibrary("System.framework/System")
else:
print cdll.LoadLibrary("libm.so")
print cdll.LoadLibrary("libcrypt.so")
print find_library("crypt")
示例13: test
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def test():
from ctypes import cdll
if os.name == "nt":
print(cdll.msvcrt)
print(cdll.load("msvcrt"))
print(find_library("msvcrt"))
if os.name == "posix":
# find and load_version
print(find_library("m"))
print(find_library("c"))
print(find_library("bz2"))
# getattr
## print cdll.m
## print cdll.bz2
# load
if sys.platform == "darwin":
print(cdll.LoadLibrary("libm.dylib"))
print(cdll.LoadLibrary("libcrypto.dylib"))
print(cdll.LoadLibrary("libSystem.dylib"))
print(cdll.LoadLibrary("System.framework/System"))
else:
print(cdll.LoadLibrary("libm.so"))
print(cdll.LoadLibrary("libcrypt.so"))
print(find_library("crypt"))
示例14: __init__
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def __init__(self, dgtboard: DgtBoard):
super(DgtPi, self).__init__(dgtboard)
self.lib_lock = Lock()
self.lib = cdll.LoadLibrary('etc/dgtpicom.x86.so' if machine() == 'x86_64' else 'etc/dgtpicom.so')
# keep the last time to find out errorous DGT_MSG_BWTIME messages (error: current time > last time)
self.r_time = 3600 * 10 # max value cause 10h cant be reached by clock
self.l_time = 3600 * 10 # max value cause 10h cant be reached by clock
self.in_settime = False # this is true between set_clock and clock_start => use set values instead of clock
self._startup_i2c_clock()
incoming_clock_thread = Timer(0, self._process_incoming_clock_forever)
incoming_clock_thread.start()
示例15: __init__
# 需要导入模块: from ctypes import cdll [as 别名]
# 或者: from ctypes.cdll import LoadLibrary [as 别名]
def __init__(self,lib_name=CATALOG1_LIB):
# Get the catalog1 sign function:
self._catalog1_lib = cdll.LoadLibrary(lib_name)
self._csign = self._catalog1_lib.sign
# Return value is an integer:
self._csign.restype = ctypes.c_int32