當前位置: 首頁>>代碼示例>>Python>>正文


Python ctypes.set_errno方法代碼示例

本文整理匯總了Python中ctypes.set_errno方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes.set_errno方法的具體用法?Python ctypes.set_errno怎麽用?Python ctypes.set_errno使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ctypes的用法示例。


在下文中一共展示了ctypes.set_errno方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_errno

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import set_errno [as 別名]
def set_errno(self, value):
        ctypes.set_errno(value) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:4,代碼來源:backend_ctypes.py

示例2: _sem_timedwait

# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import set_errno [as 別名]
def _sem_timedwait(handle, timeout):
    t_start = time.time()
    if sys.platform != "darwin":
        sec = int(timeout)
        tv_sec = int(t_start)
        nsec = int(1e9 * (timeout - sec) + .5)
        tv_nsec = int(1e9 * (t_start - tv_sec) + .5)
        deadline = timespec(sec+tv_sec, nsec+tv_nsec)
        deadline.tv_sec += int(deadline.tv_nsec / 1000000000)
        deadline.tv_nsec %= 1000000000
        return pthread.sem_timedwait(handle, ctypes.pointer(deadline))

    # PERFORMANCE WARNING
    # No sem_timedwait on OSX so we implement our own method. This method can
    # degrade performances has the wait can have a latency up to 20 msecs
    deadline = t_start + timeout
    delay = 0
    now = time.time()
    while True:
        # Poll the sem file
        res = pthread.sem_trywait(handle)
        if res == 0:
            return 0
        else:
            e = ctypes.get_errno()
            if e != errno.EAGAIN:
                raiseFromErrno()

        # check for timeout
        now = time.time()
        if now > deadline:
            ctypes.set_errno(errno.ETIMEDOUT)
            return -1

        # calculate how much time left and check the delay is not too long
        # -- maximum is 20 msecs
        difference = (deadline - now)
        delay = min(delay, 20e-3, difference)

        # Sleep and increase delay
        time.sleep(delay)
        delay += 1e-3 
開發者ID:joblib,項目名稱:loky,代碼行數:44,代碼來源:semlock.py


注:本文中的ctypes.set_errno方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。