# Buggy code
def _load_config(self) -> None:
    """Load config, monitors, alerters and loggers."""

    config = EnvironmentAwareConfigParser()
    if not self._config_file.exists():
        raise RuntimeError(
            "Configuration file {} does not exist".format(self._config_file)
        )
    config.read(self._config_file)

    self.interval = config.getint("monitor", "interval")
    self.pidfile = config.get("monitor", "pidfile", fallback=None)
    hup_file = config.get("monitor", "hup_file", fallback=None)
    if hup_file is not None:
        self._hup_file = Path(hup_file)
        module_logger.info(
            "Watching modification time of %s; increase it to trigger a config reload",
            hup_file,
        )
        self._check_hup_file()

    if not self._no_network and config.get("monitor", "remote", fallback="0") == "1":
        self._network = True
        self._remote_port = int(config.get("monitor", "remote_port"))
        self._network_key = config.get("monitor", "key", fallback=None)
        self._network_bind_host = config.get("monitor", "bind_host", fallback="")
        self._ipv4_only = cast(bool, config.get("monitor", "ipv4_only", fallback=False))
    else:
        self._network = False

    monitors_file = Path(config.get("monitor", "monitors", fallback="monitors.ini"))
    self._load_monitors(monitors_file)
    count = self.count_monitors()
    if count == 0:
        module_logger.critical("No monitors loaded :(")
    self._load_loggers(config)
    self._load_alerters(config)
    if not self._verify_dependencies():
        raise RuntimeError("Broken dependency configuration")
    if not self.verify_alerting():
        module_logger.critical("No alerters defined and no remote logger found")
    if self._network:
        self._start_network_thread()


# Traceback (OSError)
% simplemonitor -t
[...]
2020-09-10 10:12:46     INFO (simplemonitor) Starting remote listener thread (allowing pickle data)
Traceback (most recent call last):
File "/root/.local/share/virtualenvs/sm-pip-9yYbf1A2/bin/simplemonitor", line 11, in <module>
load_entry_point('simplemonitor', 'console_scripts', 'simplemonitor')()
File "/home/james/src/simplemonitor/simplemonitor/monitor.py", line 203, in main
one_shot=options.one_shot,
File "/home/james/src/simplemonitor/simplemonitor/simplemonitor.py", line 73, in __init__
self._load_config()
File "/home/james/src/simplemonitor/simplemonitor/simplemonitor.py", line 120, in _load_config
self._start_network_thread()
File "/home/james/src/simplemonitor/simplemonitor/simplemonitor.py", line 139, in _start_network_thread
bind_host=self._network_bind_host,
File "/home/james/src/simplemonitor/simplemonitor/Loggers/network.py", line 133, in __init__
self.sock.bind((bind_host, port))
OSError: [Errno 98] Address already in use

# Fixed code
def _load_config(self) -> None:
    """Load config, monitors, alerters and loggers."""

    config = EnvironmentAwareConfigParser()
    if not self._config_file.exists():
        raise RuntimeError(
            "Configuration file {} does not exist".format(self._config_file)
        )
    config.read(self._config_file)

    self.interval = config.getint("monitor", "interval")
    self.pidfile = config.get("monitor", "pidfile", fallback=None)
    hup_file = config.get("monitor", "hup_file", fallback=None)
    if hup_file is not None:
        self._hup_file = Path(hup_file)
        module_logger.info(
            "Watching modification time of %s; increase it to trigger a config reload",
            hup_file,
        )
        self._check_hup_file()

    if not self._no_network and config.get("monitor", "remote", fallback="0") == "1":
        self._network = True
        self._remote_port = int(config.get("monitor", "remote_port"))
        self._network_key = config.get("monitor", "key", fallback=None)
        self._network_bind_host = config.get("monitor", "bind_host", fallback="")
        self._ipv4_only = cast(bool, config.get("monitor", "ipv4_only", fallback=False))
    else:
        self._network = False

    monitors_file = Path(config.get("monitor", "monitors", fallback="monitors.ini"))
    self._load_monitors(monitors_file)
    count = self.count_monitors()
    if count == 0:
        module_logger.critical("No monitors loaded :(")
    self._load_loggers(config)
    self._load_alerters(config)
    if not self._verify_dependencies():
        raise RuntimeError("Broken dependency configuration")
    if not self.verify_alerting():
        module_logger.critical("No alerters defined and no remote logger found")