Merge pull request #2535 from freqtrade/fix/quitting

Fix non-terminating bot
This commit is contained in:
hroff-1902 2019-11-17 01:15:59 +03:00 committed by GitHub
commit 8e087cb639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 6 deletions

View File

@ -27,7 +27,6 @@ def main(sysargv: List[str] = None) -> None:
""" """
return_code: Any = 1 return_code: Any = 1
worker = None
try: try:
arguments = Arguments(sysargv) arguments = Arguments(sysargv)
args = arguments.get_parsed_arg() args = arguments.get_parsed_arg()
@ -57,8 +56,6 @@ def main(sysargv: List[str] = None) -> None:
except Exception: except Exception:
logger.exception('Fatal exception!') logger.exception('Fatal exception!')
finally: finally:
if worker:
worker.exit()
sys.exit(return_code) sys.exit(return_code)

View File

@ -45,8 +45,16 @@ def start_trading(args: Dict[str, Any]) -> int:
""" """
from freqtrade.worker import Worker from freqtrade.worker import Worker
# Load and run worker # Load and run worker
worker = None
try:
worker = Worker(args) worker = Worker(args)
worker.run() worker.run()
except KeyboardInterrupt:
logger.info('SIGINT received, aborting ...')
finally:
if worker:
logger.info("worker found ... calling exit")
worker.exit()
return 0 return 0

View File

@ -8,7 +8,8 @@ from freqtrade import OperationalException
from freqtrade.state import RunMode from freqtrade.state import RunMode
from freqtrade.utils import (setup_utils_configuration, start_create_userdir, from freqtrade.utils import (setup_utils_configuration, start_create_userdir,
start_download_data, start_list_exchanges, start_download_data, start_list_exchanges,
start_list_markets, start_list_timeframes) start_list_markets, start_list_timeframes,
start_trading)
from tests.conftest import get_args, log_has, patch_exchange from tests.conftest import get_args, log_has, patch_exchange
@ -24,6 +25,29 @@ def test_setup_utils_configuration():
assert config['exchange']['secret'] == '' assert config['exchange']['secret'] == ''
def test_start_trading_fail(mocker):
mocker.patch("freqtrade.worker.Worker.run", MagicMock(side_effect=OperationalException))
mocker.patch("freqtrade.worker.Worker.__init__", MagicMock(return_value=None))
exitmock = mocker.patch("freqtrade.worker.Worker.exit", MagicMock())
args = [
'trade',
'-c', 'config.json.example'
]
with pytest.raises(OperationalException):
start_trading(get_args(args))
assert exitmock.call_count == 1
exitmock.reset_mock()
mocker.patch("freqtrade.worker.Worker.__init__", MagicMock(side_effect=OperationalException))
with pytest.raises(OperationalException):
start_trading(get_args(args))
assert exitmock.call_count == 0
def test_list_exchanges(capsys): def test_list_exchanges(capsys):
args = [ args = [