本文整理汇总了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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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)
示例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
示例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
示例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)