我使用Pythonretrying
库来等待并在服务器处于DDoS保护时重试下载,但我的问题是,当所有重试失败时,如何抛出异常?在
在我的代码中,download(symbol)
函数可能引发DDoSProtection
异常。如果是这种情况,我想启动重试,如果stop_max_attempt_number
重试失败,则引发downloadError()
异常。在
def retry_if_ddospro_error(exception):
"""Return True if we should retry (in this case when it's an DDoSProtection), False otherwise"""
return isinstance(exception, DDoSProtection)
@retry(retry_on_exception = retry_if_ddospro_error, stop_max_attempt_number = 3, wait_fixed=3000)
def download (symbol):
ls = exchange.fetch_ohlcv(symbol) # Might raise DDoSProtection
# RETRY
if retry_fail:
# RAISE new exception in order to log error into database
raise downloadError('Exchange is in DDoS protection')
编辑:删除我示例中的try
except
。在
目前没有回答
相关问题 更多 >
编程相关推荐