1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-14 11:49:26 +08:00

add: migrate power limit and exercise delay

This commit is contained in:
0O0o0oOoO00
2025-09-14 17:57:06 +08:00
parent a5b77b50dd
commit ff4026fa91
51 changed files with 1630 additions and 0 deletions

View File

@@ -157,3 +157,28 @@ class Timer:
return f'Timer(limit={round(self.current(), 3)}/{self.limit}, count={self._reach_count}/{self.count})'
__repr__ = __str__
def timeout(_function, timeout_sec=30.0, *args, **kwargs):
"""Won't kill that task until it finishes"""
from threading import Thread
from module.logger import logger
def function_timeout(_func):
t0 = time.time()
success = True
p = Thread(target=_func, args=args, kwargs=kwargs)
p.start()
p.join(timeout_sec)
if p.is_alive():
success = False
t1 = time.time()
if t1 - t0 < 10:
success = False
_success = 'Done' if success else 'Failed'
logger.hr(f'{_func.__name__}: {_success} in {str(round(t1 - t0, 1))}s', 1)
if not success:
return True
return False
return function_timeout(_function)