# Buggy code
def exit(self):
    # Tell systemd that we are exiting now
    if self._sd_notify:
        logger.debug("sd_notify: STOPPING=1")
        self._sd_notify.notify("STOPPING=1")

    if self.freqtrade:
        self.freqtrade.rpc.send_msg(
            {"type": RPCMessageType.STATUS_NOTIFICATION, "status": "process died"}
        )
        self.freqtrade.cleanup()


# Traceback (AttributeError)
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'

# Fixed code
def exit(self) -> None:
    # Tell systemd that we are exiting now
    if self._sd_notify:
        logger.debug("sd_notify: STOPPING=1")
        self._sd_notify.notify("STOPPING=1")

    if self.freqtrade:
        self.freqtrade.rpc.send_msg(
            {"type": RPCMessageType.STATUS_NOTIFICATION, "status": "process died"}
        )
        self.freqtrade.cleanup()