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


Python ctypes.get_errno方法代码示例

本文整理汇总了Python中ctypes.get_errno方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.get_errno方法的具体用法?Python ctypes.get_errno怎么用?Python ctypes.get_errno使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.get_errno方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _remove_watch_for_path

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def _remove_watch_for_path(self, path):
    logging.debug('_remove_watch_for_path(%r)', path)
    wd = self._directory_to_watch_descriptor[path]

    if InotifyFileWatcher._libc.inotify_rm_watch(self._inotify_fd, wd) < 0:
      # If the directory is deleted then the watch will removed automatically
      # and inotify_rm_watch will fail. Just log the error.
      logging.debug('inotify_rm_watch failed for %r: %d [%r]',
                    path,
                    ctypes.get_errno(),
                    errno.errorcode[ctypes.get_errno()])

    parent_path = os.path.dirname(path)
    if parent_path in self._directory_to_subdirs:
      self._directory_to_subdirs[parent_path].remove(path)

    # _directory_to_subdirs must be copied because it is mutated in the
    # recursive call.
    for subdir in frozenset(self._directory_to_subdirs[path]):
      self._remove_watch_for_path(subdir)

    del self._watch_to_directory[wd]
    del self._directory_to_watch_descriptor[path]
    del self._directory_to_subdirs[path] 
开发者ID:elsigh,项目名称:browserscope,代码行数:26,代码来源:inotify_file_watcher.py

示例2: _create_file_from_fd

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def _create_file_from_fd(pfd):
    """Validates file description and creates a file-like object"""
    # -1 is returned on error: http://man7.org/linux/man-pages/man2/open.2.html#RETURN_VALUE
    if pfd == -1:
        INVALID_ARG_ERRNO = 22
        errno = ctypes.get_errno()
        if errno == INVALID_ARG_ERRNO:
            raise UnableToOpenPerfEvents('Invalid perf event file descriptor: {}, {}. '
                                         'For cgroup based perf counters it may indicate there is '
                                         'no enough hardware counters for measure all metrics!'
                                         'If traceback shows problem in perf_uncore '
                                         'it could be problem with PERF_FORMAT_GROUP in'
                                         'perf_event_attr structure for perf_event_open syscall.'
                                         'Older kernel cannot handle with extended format group.'
                                         'Kernel cannot be 3.10.0-862.el7.x86_64 or lower.'
                                         ''.format(errno, os.strerror(errno)))
        else:
            raise UnableToOpenPerfEvents('Invalid perf event file descriptor: {}, {}.'
                                         .format(errno, os.strerror(errno)))
    return os.fdopen(pfd, 'rb') 
开发者ID:intel,项目名称:workload-collocation-agent,代码行数:22,代码来源:perf.py

示例3: _migrate_page_call

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def _migrate_page_call(pid, max_node, old_nodes, new_node) -> int:
    """Wrapper on migrate_pages function using libc syscall"""

    pid = int(pid)
    max = ctypes.c_ulong(max_node + 1)
    old = ctypes.pointer(ctypes.c_ulong(old_nodes))
    new = ctypes.pointer(ctypes.c_ulong(new_node))

    # Example memory_migrate(256, pid, 5, 13 -> b'1101', 2 -> b'0010')
    result = LIBC.syscall(NR_MIGRATE_PAGES, pid, max, old, new)

    if result == -1:
        errno = ctypes.get_errno()
        raise UnableToMigratePages('Unable to migrate pages: {}, {}.'
                                   .format(errno, os.strerror(errno)))
    log.log(TRACE, 'Number of not moved pages (return from migrate_pages syscall): %d', result)
    return result 
开发者ID:intel,项目名称:workload-collocation-agent,代码行数:19,代码来源:cgroups_allocations.py

示例4: monotonicTime

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def monotonicTime(self, asSeconds = True):
        t = timespec()
        if self.clock_gettime(rmMonotonicTime.CLOCK_MONOTONIC_RAW , ctypes.pointer(t)) != 0:
            errno_ = ctypes.get_errno()
            if self.fallback:
                log.info("Monotonic Clock Error ! Reverting to time.time() fallback")
                return self.monotonicFallback(asSeconds)
            else:
                raise OSError(errno_, os.strerror(errno_))

        if asSeconds:
            return t.tv_sec

        return t.tv_sec + t.tv_nsec * 1e-9


#-----------------------------------------------------------------------------------------------
#
#
# 
开发者ID:sprinkler,项目名称:rainmachine-developer-resources,代码行数:22,代码来源:rmTimeUtils.py

示例5: _check_errno

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def _check_errno(result, func, arguments):
    assert func.restype in [c_int, c_void_p]
    if (func.restype == c_int and result == -1) or (
        func.restype == c_void_p and c_void_p(result).value == c_void_p(-1).value
    ):
        errno = _ctypes.get_errno()
        try:
            func_name = func.__name__
        except AttributeError:
            func_name = "__unknown__"
        msg = (
            func_name
            + "("
            + ", ".join(map(str, arguments))
            + ") failed: "
            + _os.strerror(errno)
        )
        raise OSError(errno, msg)
    return result


# off_t is a signed integer type required for mmap.
# In my tests it is equal to long on both 32bit and 64bit x86 Linux. 
开发者ID:sosy-lab,项目名称:benchexec,代码行数:25,代码来源:libc.py

示例6: _ptrace

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def _ptrace(self, attach):
        op = ctypes.c_int(PTRACE_ATTACH if attach else PTRACE_DETACH)
        c_pid = c_pid_t(self.pid)
        null = ctypes.c_void_p()

        if not attach:
            os.kill(self.pid, signal.SIGSTOP)
            os.waitpid(self.pid, 0)

        err = c_ptrace(op, c_pid, null, null)

        if not attach:
            os.kill(self.pid, signal.SIGCONT)

        if err != 0:
            raise OSError("%s: %s"%(
                'PTRACE_ATTACH' if attach else 'PTRACE_DETACH',
                errno.errorcode.get(ctypes.get_errno(), 'UNKNOWN')
            )) 
开发者ID:n1nj4sec,项目名称:memorpy,代码行数:21,代码来源:LinProcess.py

示例7: open_dev

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def open_dev(bt_device_id):
    """Open hci device socket."""
    # pylint: disable=no-member
    sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)

    # Unlike Linux, FreeBSD has separate numbering depending on hardware
    # (ubt - USB bluetooth - is the most common, so convert numbers to that)
    if not isinstance(bt_device_id, str):
        bt_device_id = 'ubt{}hci'.format(bt_device_id)

    # Python's BTPROTO_HCI address parsing is busted: https://bugs.python.org/issue41130
    adr = SockaddrHci(ctypes.sizeof(SockaddrHci), socket.AF_BLUETOOTH, bt_device_id.ljust(32, '\0').encode('utf-8'))
    if libc.bind(sock.fileno(), ctypes.pointer(adr), ctypes.sizeof(SockaddrHci)) != 0:
        raise ConnectionError(ctypes.get_errno(), os.strerror(ctypes.get_errno()))
    if libc.connect(sock.fileno(), ctypes.pointer(adr), ctypes.sizeof(SockaddrHci)) != 0:
        raise ConnectionError(ctypes.get_errno(), os.strerror(ctypes.get_errno()))
    # pylint: enable=no-member

    fltr = HciRawFilter(0, NG_HCI_EVENT_MASK_LE)
    if libc.setsockopt(sock.fileno(),
                       SOL_HCI_RAW, SOL_HCI_RAW_FILTER,
                       ctypes.pointer(fltr), ctypes.sizeof(HciRawFilter)) != 0:
        raise ConnectionError(ctypes.get_errno(), os.strerror(ctypes.get_errno()))

    return sock 
开发者ID:citruz,项目名称:beacontools,代码行数:27,代码来源:freebsd.py

示例8: _sem_open

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def _sem_open(name, value=None):
    """ Construct or retrieve a semaphore with the given name

    If value is None, try to retrieve an existing named semaphore.
    Else create a new semaphore with the given value
    """
    if value is None:
        handle = pthread.sem_open(ctypes.c_char_p(name), 0)
    else:
        handle = pthread.sem_open(ctypes.c_char_p(name), SEM_OFLAG, SEM_PERM,
                                  ctypes.c_int(value))

    if handle == SEM_FAILURE:
        e = ctypes.get_errno()
        if e == errno.EEXIST:
            raise FileExistsError("a semaphore named %s already exists" % name)
        elif e == errno.ENOENT:
            raise FileNotFoundError('cannot find semaphore named %s' % name)
        elif e == errno.ENOSYS:
            raise NotImplementedError('No semaphore implementation on this '
                                      'system')
        else:
            raiseFromErrno()

    return handle 
开发者ID:joblib,项目名称:loky,代码行数:27,代码来源:semlock.py

示例9: acquire

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def acquire(self, block=True, timeout=None):
        if self.kind == RECURSIVE_MUTEX and self._is_mine():
            self.count += 1
            return True

        if block and timeout is None:
            res = pthread.sem_wait(self.handle)
        elif not block or timeout <= 0:
            res = pthread.sem_trywait(self.handle)
        else:
            res = _sem_timedwait(self.handle, timeout)
        if res < 0:
            e = ctypes.get_errno()
            if e == errno.EINTR:
                return None
            elif e in [errno.EAGAIN, errno.ETIMEDOUT]:
                return False
            raiseFromErrno()
        self.count += 1
        self.ident = get_ident()
        return True 
开发者ID:joblib,项目名称:loky,代码行数:23,代码来源:semlock.py

示例10: _is_zero

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def _is_zero(self):
        if sys.platform == 'darwin':
            # Handle broken get_value for mac ==> only Lock will work
            # as sem_get_value do not work properly
            if pthread.sem_trywait(self.handle) < 0:
                e = ctypes.get_errno()
                if e == errno.EAGAIN:
                    return True
                raise OSError(e, errno.errorcode[e])
            else:
                if pthread.sem_post(self.handle) < 0:
                    raiseFromErrno()
                return False
        else:
            value = ctypes.pointer(ctypes.c_int(-1))
            if pthread.sem_getvalue(self.handle, value) < 0:
                raiseFromErrno()
            return value.contents.value == 0 
开发者ID:joblib,项目名称:loky,代码行数:20,代码来源:semlock.py

示例11: umount

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def umount(self):
        """Unmount disk."""
        if not self.mountpoint:
            return
        signals.emit("filesystems", "pre_umount", self)
        loops = losetup.get_loop_devices()
        for l in loops:
            if loops[l].is_used() and loops[l].get_filename() == self.path:
                dev = loops[l]
                break
        s = libc.umount2(ctypes.c_char_p(b(self.mountpoint)), 0)
        if s == -1:
            excmsg = "Failed to unmount {0}: {1}"
            raise errors.OperationFailedError(
                excmsg.format(self.id, os.strerror(ctypes.get_errno())))
        if self.crypt:
            crypto.luks_close(self.id)
        if dev:
            dev.unmount()
        signals.emit("filesystems", "post_umount", self)
        self.mountpoint = None 
开发者ID:arkOScloud,项目名称:core,代码行数:23,代码来源:filesystems.py

示例12: check_errno_on_nonzero_return

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def check_errno_on_nonzero_return(result, func, *args):
    """Error checker to check the system ``errno`` as returned by
    :func:`ctypes.get_errno()`.

    If ``result`` is not ``0``, an exception according to this errno is raised.
    Otherwise nothing happens.

    """
    if result != 0:
        errnum = get_errno()
        if errnum != 0:
            raise exception_from_errno(errnum)
    return result 
开发者ID:mbusb,项目名称:multibootusb,代码行数:15,代码来源:_errorcheckers.py

示例13: check_errno_on_null_pointer_return

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def check_errno_on_null_pointer_return(result, func, *args):
    """Error checker to check the system ``errno`` as returned by
    :func:`ctypes.get_errno()`.

    If ``result`` is a null pointer, an exception according to this errno is
    raised.  Otherwise nothing happens.

    """
    # pylint: disable=invalid-name
    if not result:
        errnum = get_errno()
        if errnum != 0:
            raise exception_from_errno(errnum)
    return result 
开发者ID:mbusb,项目名称:multibootusb,代码行数:16,代码来源:_errorcheckers.py

示例14: posix_error

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def posix_error(filename):
        errno = ctypes.get_errno()
        exc = OSError(errno, strerror(errno))
        exc.filename = filename
        return exc 
开发者ID:DoTheEvo,项目名称:ANGRYsearch,代码行数:7,代码来源:scandir.py

示例15: clock_getdtime

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import get_errno [as 别名]
def clock_getdtime(type):
    t = timespec()
    if clock_gettime(type, ctypes.pointer(t)) != 0:
        errno_ = ctypes.get_errno()
        raise OSError(errno_, os.strerror(errno_))
    return float(t.tv_sec) + float(t.tv_nsec * 1e-09) 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:8,代码来源:clock_dtime.py


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