Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@exit_after(1)
def slow_fce():
time.sleep(2)
@exit_after(1)
def bad_fce():
raise ColinException("Error")
def test_timeout_dirrect():
with pytest.raises(TimeoutError):
exit_after(1)(time.sleep)(2)
def _result_generator(target, checks, timeout=None):
try:
for check in checks:
logger.debug("Checking {}".format(check.name))
try:
_timeout = timeout or check.timeout or CHECK_TIMEOUT
logger.debug("Check timeout: {}".format(_timeout))
yield exit_after(_timeout)(check.check)(target)
except TimeoutError as ex:
logger.warning(
"The check hit the timeout: {}".format(_timeout))
yield FailedCheckResult(check, logs=[str(ex)])
except Exception as ex:
tb = traceback.format_exc()
logger.warning(
"There was an error while performing check: {}".format(tb))
yield FailedCheckResult(check, logs=[str(ex)])
finally:
target.clean_up()