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


Python errno.ETIME屬性代碼示例

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


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

示例1: timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
    def decorator(func):
        def _handle_timeout(signum, frame):
            raise TimeoutError(error_message)

        def wrapper(*args, **kwargs):
            signal.signal(signal.SIGALRM, _handle_timeout)
            signal.alarm(seconds)
            try:
                result = func(*args, **kwargs)
            finally:
                signal.alarm(0)
            return result

        return wraps(func)(wrapper)

    return decorator 
開發者ID:KanoComputing,項目名稱:kano-toolset,代碼行數:19,代碼來源:timeout.py

示例2: timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
    def decorator(func):
        def _handle_timeout(signum, frame):
            raise TimeoutError(error_message)

        def wrapper(*args, **kwargs):
            #signal.signal(signal.SIGALRM, _handle_timeout)
            signal.alarm(seconds)
            try:
                result = func(*args, **kwargs)
            finally:
                signal.alarm(0)
            return result

        return wraps(func)(wrapper)

    return decorator 
開發者ID:openeventdata,項目名稱:scraper,代碼行數:19,代碼來源:scraper_sched.py

示例3: timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
    def decorator(func):
        def _handle_timeout(signum, frame):
            raise TimeoutError(error_message)
            
        def wrapper(*args, **kwargs):
            signal.signal(signal.SIGALRM, _handle_timeout)
            signal.alarm(seconds)
            try:
                result = func(*args, **kwargs)
            finally:
                signal.alarm(0)
            return result

        return wraps(func)(wrapper)

    return decorator
############################## TIMOUT 
開發者ID:rpryzant,項目名稱:neutralizing-bias,代碼行數:20,代碼來源:tag_corpusfile.py

示例4: timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def timeout(seconds=30, error_message=os.strerror(errno.ETIME)):
    def decorator(func):
        def _handle_timeout(signum, frame):
            raise TimeoutError(error_message)

        def wrapper(*args, **kwargs):
            signal.signal(signal.SIGALRM, _handle_timeout)
            signal.alarm(seconds)
            try:
                result = func(*args, **kwargs)
            finally:
                signal.alarm(0)
            return result

        return wraps(func)(wrapper)

    return decorator 
開發者ID:utkusen,項目名稱:leviathan,代碼行數:19,代碼來源:utils.py

示例5: timeout_dec

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def timeout_dec(seconds=20, error_message=os.strerror(errno.ETIME)):
    def decorator(func):
        def _handle_timeout(signum, frame):
            raise TimeoutError(error_message)

        def wrapper(*args, **kwargs):
            signal.signal(signal.SIGALRM, _handle_timeout)
            signal.alarm(seconds)
            try:
                result = func(*args, **kwargs)
            finally:
                signal.alarm(0)
            return result

        return wraps(func)(wrapper)

    return decorator 
開發者ID:jacobajit,項目名稱:AlexaBot,代碼行數:19,代碼來源:timeout_dec.py

示例6: _handle_timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def _handle_timeout(signum, frame):
    error_message = os.strerror(errno.ETIME)
    log.error("*** Timeout occurred while running a parser: %s" % error_message)
    raise RMTimeoutError(error_message) 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:6,代碼來源:rmParser.py

示例7: timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def timeout(
    seconds: int = 10,
    error_message: str = os.strerror(errno.ETIME),
    use_signals: bool = True,
) -> Callable[[Callable[..., _TimeoutFuncRetType]], Callable[..., _TimeoutFuncRetType]]:
    if use_signals:

        def decorate(
            func: Callable[..., _TimeoutFuncRetType]
        ) -> Callable[..., _TimeoutFuncRetType]:
            def _handle_timeout(signum: int, frame: FrameType) -> None:
                raise TimeoutError(error_message)

            def wrapper(*args: Any, **kwargs: Any) -> _TimeoutFuncRetType:
                signal.signal(signal.SIGALRM, _handle_timeout)
                signal.alarm(seconds)
                try:
                    result = func(*args, **kwargs)
                finally:
                    signal.alarm(0)
                return result

            return wraps(func)(wrapper)

    else:

        def decorate(
            func: Callable[..., _TimeoutFuncRetType]
        ) -> Callable[..., _TimeoutFuncRetType]:
            # https://github.com/python/mypy/issues/797
            return _Timeout(func, seconds, error_message)  # type: ignore

    return decorate 
開發者ID:Yelp,項目名稱:paasta,代碼行數:35,代碼來源:utils.py

示例8: time_limit

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def time_limit(seconds, error_message=os.strerror(errno.ETIME)):
    """Context manager for handling method timeouts.

    Usage:
        try:
            with time_limit(10):
                some_function()
        except TimeoutException:
            # error handling here

    :param int seconds: seconds before timeout.
    :param str error_message: error message.
    :raises: kale.exceptions.TimeoutException
    """

    def _handle_timeout(signum, frame):
        """Handle timout signal."""
        raise exceptions.TimeoutException(error_message)

    original_handler = signal.signal(signal.SIGALRM, _handle_timeout)
    signal.alarm(seconds)
    try:
        yield
    finally:
        # Reset original handler.
        signal.signal(signal.SIGALRM, original_handler)
        # Remove signal.
        signal.alarm(0) 
開發者ID:Nextdoor,項目名稱:ndkale,代碼行數:30,代碼來源:timeout.py

示例9: timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
    def decorator(func):
        def _handle_timeout(signum, frame):
            raise TimeoutError(error_message)

        def wrapper(*args, **kwargs):
            signal.signal(signal.SIGALRM, _handle_timeout)
            signal.alarm(seconds)
            try:
                result = func(*args, **kwargs)
            finally:
                signal.alarm(0)
            return result
        return wraps(func)(wrapper)
    return decorator 
開發者ID:iclab,項目名稱:centinel,代碼行數:17,代碼來源:foctor_core.py

示例10: local_timeout

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def local_timeout(seconds=10, error_message=os.strerror(errno.ETIME)):
    def decorator(func):
        def _handle_timeout(signum, frame):
            raise LocalTimeoutError(error_message)

        def wrapper(*args, **kwargs):
            signal.signal(signal.SIGALRM, _handle_timeout)
            signal.alarm(seconds)
            try:
                result = func(*args, **kwargs)
            finally:
                signal.alarm(0)
            return result
        return wraps(func)(wrapper)
    return decorator 
開發者ID:iclab,項目名稱:centinel,代碼行數:17,代碼來源:foctor_authentication.py

示例11: test_3_closed

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ETIME [as 別名]
def test_3_closed(self):
        if sys.platform.startswith("win"): # no SIGALRM on windows
            return
        rsock = LoopSocket()
        wsock = LoopSocket()
        rsock.link(wsock)
        p = Packetizer(wsock)
        p.set_log(util.get_logger('paramiko.transport'))
        p.set_hexdump(True)
        encryptor = Cipher(
            algorithms.AES(zero_byte * 16),
            modes.CBC(x55 * 16),
            backend=default_backend()
        ).encryptor()
        p.set_outbound_cipher(encryptor, 16, sha1, 12, x1f * 20)

        # message has to be at least 16 bytes long, so we'll have at least one
        # block of data encrypted that contains zero random padding bytes
        m = Message()
        m.add_byte(byte_chr(100))
        m.add_int(100)
        m.add_int(1)
        m.add_int(900)
        wsock.send = lambda x: 0
        from functools import wraps
        import errno
        import os
        import signal

        class TimeoutError(Exception):
            def __init__(self, error_message):
                if hasattr(errno, 'ETIME'):
                    self.message = os.sterror(errno.ETIME)
                else:
                    self.messaage = error_message

        def timeout(seconds=1, error_message='Timer expired'):
            def decorator(func):
                def _handle_timeout(signum, frame):
                    raise TimeoutError(error_message)

                def wrapper(*args, **kwargs):
                    signal.signal(signal.SIGALRM, _handle_timeout)
                    signal.alarm(seconds)
                    try:
                        result = func(*args, **kwargs)
                    finally:
                        signal.alarm(0)
                    return result

                return wraps(func)(wrapper)

            return decorator
        send = timeout()(p.send_message)
        self.assertRaises(EOFError, send, m) 
開發者ID:hpe-storage,項目名稱:python-hpedockerplugin,代碼行數:57,代碼來源:test_packetizer.py


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