Repository: freqtrade/freqtrade

Issue:
hangin after /reload_conf
## Step 1: Have you search for this issue before posting it? Yep

## Step 2: Describe your environment

  * Python Version: Python 3.7.2 (`python -V`)
  * CCXT version: ccxt==1.18.492 (`pip freeze | grep ccxt`)
  * Branch: Develop
  * Last Commit ID: 6166e194058f2e091989cc61104bf45aa961625f (`git log --format="%H" -n 1`)
  
## Step 3: Describe the problem:

After changing the config file, trying to reload conf.

### Steps to reproduce:

1. on Telegram
/stop
Status: stopping trader ...
Status: stopped
/reload_conf
Status: reloading config ...
Status: reload_conf
Status: config reloaded
  
### Observed Results:

  * Start the process and hang-up with an error
2019-04-28 20:17:12,865 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'config reloaded'}
2019-04-28 20:17:13,143 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/main.py", line 42, in main
    worker.run()
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/worker.py", line 72, in run
    state = self._worker(old_state=state)
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/worker.py", line 82, in _worker
    state = self.freqtrade.state
AttributeError: 'NoneType' object has no attribute 'state'

  * What did you expect to happen?

### Relevant code exceptions or logs:

  ```
2019-04-28 20:16:48,533 - freqtrade.rpc.telegram - INFO - Executing handler: _stop for chat_id: 263998                                                                                                         014
2019-04-28 20:16:51,558 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currenc                                                                                                         ies. Trying again..
2019-04-28 20:16:51,562 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'st                                                                                                         atus': 'stopped'}
2019-04-28 20:16:51,719 - freqtrade.worker - INFO - Changing state to: STOPPED
2019-04-28 20:16:57,213 - freqtrade.rpc.telegram - INFO - Executing handler: _reload_conf for chat_id:                                                                                                          263998014
2019-04-28 20:17:01,720 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'st                                                                                                         atus': 'reload_conf'}
2019-04-28 20:17:01,891 - freqtrade.worker - INFO - Changing state to: RELOAD_CONF
2019-04-28 20:17:01,891 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2019-04-28 20:17:01,891 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
2019-04-28 20:17:02,397 - freqtrade.configuration - INFO - Using config: config.json ...
2019-04-28 20:17:02,398 - freqtrade.configuration - INFO - Validating configuration ...
2019-04-28 20:17:02,399 - freqtrade.configuration - INFO - Verbosity set to 0
2019-04-28 20:17:02,399 - freqtrade.configuration - INFO - Parameter --db-url detected ...
2019-04-28 20:17:02,400 - freqtrade.configuration - INFO - Dry run is disabled
2019-04-28 20:17:02,400 - freqtrade.configuration - INFO - Using DB: "sqlite:///tradesv3.real_kraken.s                                                                                                         qlite"
2019-04-28 20:17:02,400 - freqtrade.configuration - INFO - Using max_open_trades: 5 ...
2019-04-28 20:17:02,400 - freqtrade.configuration - INFO - Using data folder: user_data/data/kraken ..                                                                                                         .
2019-04-28 20:17:02,400 - freqtrade.freqtradebot - INFO - Starting freqtrade 0.18.5-dev
2019-04-28 20:17:02,474 - freqtrade.resolvers.strategy_resolver - INFO - Using resolved strategy Defau                                                                                                         ltStrategy from '/mnt/d/gitcoderepo/freqtrade/freqtrade/strategy'
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'ticker_int                                                                                                         erval' with value in config file: 5m.
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'trailing_s                                                                                                         top' with value in config file: False.
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'stake_curr                                                                                                         ency' with value in config file: EUR.
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'stake_amou                                                                                                         nt' with value in config file: 10.
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using minimal_roi: {                                                                                                         '40': 0.0, '30': 0.01, '20': 0.02, '0': 0.04}
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using ticker_interva                                                                                                         l: 5m
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stoploss: -0.1
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_stop:                                                                                                          False
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_stop_                                                                                                         positive_offset: 0.0
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_only_                                                                                                         offset_is_reached: False
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using process_only_n                                                                                                         ew_candles: False
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_types: {                                                                                                         'buy': 'limit', 'sell': 'limit', 'stoploss': 'limit', 'stoploss_on_exchange': False}
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_time_in_                                                                                                         force: {'buy': 'gtc', 'sell': 'gtc'}
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stake_currency                                                                                                         : EUR
2019-04-28 20:17:02,477 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stake_amount:                                                                                                          10
2019-04-28 20:17:02,477 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using use_sell_signa                                                                                                         l: False
2019-04-28 20:17:02,477 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using sell_profit_on                                                                                                         ly: False
2019-04-28 20:17:02,477 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using ignore_roi_if_                                                                                                         buy_signal: False
2019-04-28 20:17:02,477 - freqtrade.rpc.rpc_manager - INFO - Enabling rpc.telegram ...
2019-04-28 20:17:02,481 - freqtrade.rpc.telegram - INFO - rpc.telegram is listening for following comm                                                                                                         ands: [['status'], ['profit'], ['balance'], ['start'], ['stop'], ['forcesell'], ['forcebuy'], ['perfor                                                                                                         mance'], ['daily'], ['count'], ['reload_conf'], ['stopbuy'], ['whitelist'], ['blacklist'], ['edge'], [                                                                                                         'help'], ['version']]
2019-04-28 20:17:03,552 - freqtrade.exchange.exchange - INFO - Applying additional ccxt config: {'enab                                                                                                         leRateLimit': True}
2019-04-28 20:17:03,554 - freqtrade.exchange.exchange - INFO - Applying additional ccxt config: {'enab                                                                                                         leRateLimit': True, 'rateLimit': 1000}
2019-04-28 20:17:03,568 - freqtrade.exchange.exchange - INFO - Using Exchange "Kraken"
2019-04-28 20:17:10,916 - freqtrade.resolvers.exchange_resolver - INFO - Using resolved exchange Kraken
2019-04-28 20:17:12,819 - freqtrade.wallets - INFO - Wallets synced.
2019-04-28 20:17:12,820 - freqtrade.resolvers.pairlist_resolver - WARNING - Path "user_data/pairlist" does not exist
2019-04-28 20:17:12,857 - freqtrade.resolvers.pairlist_resolver - INFO - Using resolved pairlist StaticPairList from '/mnt/d/gitcoderepo/freqtrade/freqtrade/pairlist'
2019-04-28 20:17:12,865 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'config reloaded'}
2019-04-28 20:17:13,143 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/main.py", line 42, in main
    worker.run()
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/worker.py", line 72, in run
    state = self._worker(old_state=state)
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/worker.py", line 82, in _worker
    state = self.freqtrade.state
AttributeError: 'NoneType' object has no attribute 'state'


  ```

hangin after /reload_conf
## Step 1: Have you search for this issue before posting it? Yep

## Step 2: Describe your environment

  * Python Version: Python 3.7.2 (`python -V`)
  * CCXT version: ccxt==1.18.492 (`pip freeze | grep ccxt`)
  * Branch: Develop
  * Last Commit ID: 6166e194058f2e091989cc61104bf45aa961625f (`git log --format="%H" -n 1`)
  
## Step 3: Describe the problem:

After changing the config file, trying to reload conf.

### Steps to reproduce:

1. on Telegram
/stop
Status: stopping trader ...
Status: stopped
/reload_conf
Status: reloading config ...
Status: reload_conf
Status: config reloaded
  
### Observed Results:

  * Start the process and hang-up with an error
2019-04-28 20:17:12,865 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'config reloaded'}
2019-04-28 20:17:13,143 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/main.py", line 42, in main
    worker.run()
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/worker.py", line 72, in run
    state = self._worker(old_state=state)
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/worker.py", line 82, in _worker
    state = self.freqtrade.state
AttributeError: 'NoneType' object has no attribute 'state'

  * What did you expect to happen?

### Relevant code exceptions or logs:

  ```
2019-04-28 20:16:48,533 - freqtrade.rpc.telegram - INFO - Executing handler: _stop for chat_id: 263998                                                                                                         014
2019-04-28 20:16:51,558 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currenc                                                                                                         ies. Trying again..
2019-04-28 20:16:51,562 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'st                                                                                                         atus': 'stopped'}
2019-04-28 20:16:51,719 - freqtrade.worker - INFO - Changing state to: STOPPED
2019-04-28 20:16:57,213 - freqtrade.rpc.telegram - INFO - Executing handler: _reload_conf for chat_id:                                                                                                          263998014
2019-04-28 20:17:01,720 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'st                                                                                                         atus': 'reload_conf'}
2019-04-28 20:17:01,891 - freqtrade.worker - INFO - Changing state to: RELOAD_CONF
2019-04-28 20:17:01,891 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2019-04-28 20:17:01,891 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
2019-04-28 20:17:02,397 - freqtrade.configuration - INFO - Using config: config.json ...
2019-04-28 20:17:02,398 - freqtrade.configuration - INFO - Validating configuration ...
2019-04-28 20:17:02,399 - freqtrade.configuration - INFO - Verbosity set to 0
2019-04-28 20:17:02,399 - freqtrade.configuration - INFO - Parameter --db-url detected ...
2019-04-28 20:17:02,400 - freqtrade.configuration - INFO - Dry run is disabled
2019-04-28 20:17:02,400 - freqtrade.configuration - INFO - Using DB: "sqlite:///tradesv3.real_kraken.s                                                                                                         qlite"
2019-04-28 20:17:02,400 - freqtrade.configuration - INFO - Using max_open_trades: 5 ...
2019-04-28 20:17:02,400 - freqtrade.configuration - INFO - Using data folder: user_data/data/kraken ..                                                                                                         .
2019-04-28 20:17:02,400 - freqtrade.freqtradebot - INFO - Starting freqtrade 0.18.5-dev
2019-04-28 20:17:02,474 - freqtrade.resolvers.strategy_resolver - INFO - Using resolved strategy Defau                                                                                                         ltStrategy from '/mnt/d/gitcoderepo/freqtrade/freqtrade/strategy'
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'ticker_int                                                                                                         erval' with value in config file: 5m.
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'trailing_s                                                                                                         top' with value in config file: False.
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'stake_curr                                                                                                         ency' with value in config file: EUR.
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'stake_amou                                                                                                         nt' with value in config file: 10.
2019-04-28 20:17:02,475 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using minimal_roi: {                                                                                                         '40': 0.0, '30': 0.01, '20': 0.02, '0': 0.04}
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using ticker_interva                                                                                                         l: 5m
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stoploss: -0.1
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_stop:                                                                                                          False
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_stop_                                                                                                         positive_offset: 0.0
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_only_                                                                                                         offset_is_reached: False
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using process_only_n                                                                                                         ew_candles: False
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_types: {                                                                                                         'buy': 'limit', 'sell': 'limit', 'stoploss': 'limit', 'stoploss_on_exchange': False}
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_time_in_                                                                                                         force: {'buy': 'gtc', 'sell': 'gtc'}
2019-04-28 20:17:02,476 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stake_currency                                                                                                         : EUR
2019-04-28 20:17:02,477 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stake_amount:                                                                                                          10
2019-04-28 20:17:02,477 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using use_sell_signa                                                                                                         l: False
2019-04-28 20:17:02,477 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using sell_profit_on                                                                                                         ly: False
2019-04-28 20:17:02,477 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using ignore_roi_if_                                                                                                         buy_signal: False
2019-04-28 20:17:02,477 - freqtrade.rpc.rpc_manager - INFO - Enabling rpc.telegram ...
2019-04-28 20:17:02,481 - freqtrade.rpc.telegram - INFO - rpc.telegram is listening for following comm                                                                                                         ands: [['status'], ['profit'], ['balance'], ['start'], ['stop'], ['forcesell'], ['forcebuy'], ['perfor                                                                                                         mance'], ['daily'], ['count'], ['reload_conf'], ['stopbuy'], ['whitelist'], ['blacklist'], ['edge'], [                                                                                                         'help'], ['version']]
2019-04-28 20:17:03,552 - freqtrade.exchange.exchange - INFO - Applying additional ccxt config: {'enab                                                                                                         leRateLimit': True}
2019-04-28 20:17:03,554 - freqtrade.exchange.exchange - INFO - Applying additional ccxt config: {'enab                                                                                                         leRateLimit': True, 'rateLimit': 1000}
2019-04-28 20:17:03,568 - freqtrade.exchange.exchange - INFO - Using Exchange "Kraken"
2019-04-28 20:17:10,916 - freqtrade.resolvers.exchange_resolver - INFO - Using resolved exchange Kraken
2019-04-28 20:17:12,819 - freqtrade.wallets - INFO - Wallets synced.
2019-04-28 20:17:12,820 - freqtrade.resolvers.pairlist_resolver - WARNING - Path "user_data/pairlist" does not exist
2019-04-28 20:17:12,857 - freqtrade.resolvers.pairlist_resolver - INFO - Using resolved pairlist StaticPairList from '/mnt/d/gitcoderepo/freqtrade/freqtrade/pairlist'
2019-04-28 20:17:12,865 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'config reloaded'}
2019-04-28 20:17:13,143 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/main.py", line 42, in main
    worker.run()
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/worker.py", line 72, in run
    state = self._worker(old_state=state)
  File "/mnt/d/gitcoderepo/freqtrade/freqtrade/worker.py", line 82, in _worker
    state = self.freqtrade.state
AttributeError: 'NoneType' object has no attribute 'state'


  ```



Discussion:

Resolving patch:
diff --git a/freqtrade/worker.py b/freqtrade/worker.py
--- a/freqtrade/worker.py
+++ b/freqtrade/worker.py
@@ -39,7 +39,7 @@ def __init__(self, args: Namespace, config=None) -> None:
             logger.debug("sd_notify: READY=1")
             self._sd_notify.notify("READY=1")
 
-    def _init(self, reconfig: bool):
+    def _init(self, reconfig: bool) -> None:
         """
         Also called from the _reconfigure() method (with reconfig=True).
         """
@@ -63,17 +63,17 @@ def state(self) -> State:
         return self.freqtrade.state
 
     @state.setter
-    def state(self, value: State):
+    def state(self, value: State) -> None:
         self.freqtrade.state = value
 
-    def run(self):
+    def run(self) -> None:
         state = None
         while True:
             state = self._worker(old_state=state)
             if state == State.RELOAD_CONF:
-                self.freqtrade = self._reconfigure()
+                self._reconfigure()
 
-    def _worker(self, old_state: State, throttle_secs: Optional[float] = None) -> State:
+    def _worker(self, old_state: Optional[State], throttle_secs: Optional[float] = None) -> State:
         """
         Trading routine that must be run at each loop
         :param old_state: the previous service state from the previous call
@@ -148,7 +148,7 @@ def _process(self) -> bool:
 #            state_changed = True
         return state_changed
 
-    def _reconfigure(self):
+    def _reconfigure(self) -> None:
         """
         Cleans up current freqtradebot instance, reloads the configuration and
         replaces it with the new instance
@@ -174,7 +174,7 @@ def _reconfigure(self):
             logger.debug("sd_notify: READY=1")
             self._sd_notify.notify("READY=1")
 
-    def exit(self):
+    def exit(self) -> None:
         # Tell systemd that we are exiting now
         if self._sd_notify:
             logger.debug("sd_notify: STOPPING=1")


Test patch: