当前位置: 首页>>代码示例>>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;未经允许,请勿转载。