From abcdbcfd39c20d251694b83206f784b483aacb96 Mon Sep 17 00:00:00 2001 From: Anton Ermak Date: Wed, 10 Jan 2018 17:37:49 +0700 Subject: [PATCH] Set requests default timeout --- freqtrade/main.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/freqtrade/main.py b/freqtrade/main.py index 5e8680b85..efd0d7c44 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -10,6 +10,7 @@ from datetime import datetime from typing import Dict, Optional, List import requests +from requests.adapters import TimeoutSauce from cachetools import cached, TTLCache from freqtrade import __version__, exchange, persistence, rpc, DependencyException, \ @@ -24,6 +25,23 @@ logger = logging.getLogger('freqtrade') _CONF = {} +DEFAULT_TIMEOUT = 120 + + +# Set requests default timeout (fix for #127) +class DefaultTimeout(TimeoutSauce): + def __init__(self, *args, **kwargs): + connect = kwargs.get('connect', DEFAULT_TIMEOUT) + read = kwargs.get('read', connect) + if connect is None: + connect = DEFAULT_TIMEOUT + if read is None: + read = connect + super(DefaultTimeout, self).__init__(connect=connect, read=read) + + +requests.adapters.TimeoutSauce = DefaultTimeout + def refresh_whitelist(whitelist: List[str]) -> List[str]: """