mirror of
https://github.com/onyx-and-iris/xair-api-python.git
synced 2024-11-21 12:30:46 +00:00
timeout decorator func added to util
This commit is contained in:
parent
69cabb3db0
commit
718ecbd982
@ -1,6 +1,35 @@
|
||||
import functools
|
||||
import time
|
||||
from math import exp, log
|
||||
|
||||
from .errors import XAirRemoteConnectionTimeoutError
|
||||
|
||||
|
||||
def timeout(func):
|
||||
"""
|
||||
Times out the login function once time elapsed exceeds remote.connect_timeout.
|
||||
"""
|
||||
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
remote, *_ = args
|
||||
|
||||
err = None
|
||||
start = time.time()
|
||||
while time.time() < start + remote.connect_timeout:
|
||||
try:
|
||||
func(*args, **kwargs)
|
||||
remote.logger.debug(f"login time: {round(time.time() - start, 2)}")
|
||||
err = None
|
||||
break
|
||||
except XAirRemoteConnectionTimeoutError as e:
|
||||
err = e
|
||||
continue
|
||||
if err:
|
||||
raise err
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def lin_get(min, max, val):
|
||||
return min + (max - min) * val
|
||||
|
Loading…
Reference in New Issue
Block a user