# Buggy code
def __init__(self, run=True):
    self.client = MaestralApiClient()

    # periodically check for updates and refresh account info
    self.update_thread = Thread(
        name="Maestral update check",
        target=self._periodic_refresh,
        daemon=True,
    )
    self.update_thread.start()

    # monitor needs to be created before any decorators are called
    self.monitor = MaestralMonitor(self.client)
    self.sync = self.monitor.sync

    if NOTIFY_SOCKET and system_notifier:
        # notify systemd that we have successfully started
        system_notifier.notify("READY=1")

    if WATCHDOG_USEC and int(WATCHDOG_PID) == os.getpid() and system_notifier:
        # notify systemd periodically that we are still alive
        self.watchdog_thread = Thread(
            name="Maestral watchdog",
            target=self._periodic_watchdog,
            daemon=True,
        )
        self.update_thread.start()

    if run:
        # if `run == False`, make sure that you manually run the setup
        # before calling `start_sync`
        if self.pending_dropbox_folder():
            self.create_dropbox_directory()
            self.set_excluded_folders()

            self.sync.last_cursor = ""
            self.sync.last_sync = 0

        self.start_sync()


# Traceback (RuntimeError)
Oct 22 21:59:54 dolores systemd[1126]: Starting Maestral - a Dropbox clone...
Oct 22 21:59:55 dolores systemd[1126]: Started Maestral - a Dropbox clone.
Oct 22 21:59:55 dolores maestral[5770]: Traceback (most recent call last):
Oct 22 21:59:55 dolores maestral[5770]:   File "/nix/store/vrllbj5ial3g70b2wd2bxmx01rxv32yw-maestral-0.4.1/lib/python3.7/site-packages/maestral/sync/daemon.py", line 119, in start_maestral_daemon
Oct 22 21:59:55 dolores maestral[5770]:     m = ExposedMaestral(run=run)
Oct 22 21:59:55 dolores maestral[5770]:   File "/nix/store/vrllbj5ial3g70b2wd2bxmx01rxv32yw-maestral-0.4.1/lib/python3.7/site-packages/maestral/sync/main.py", line 255, in __init__
Oct 22 21:59:55 dolores maestral[5770]:     self.update_thread.start()
Oct 22 21:59:55 dolores maestral[5770]:   File "/nix/store/8lhmyjarm73453f2mdz0xli9w8sy0wvh-python3-3.7.4/lib/python3.7/threading.py", line 848, in start
Oct 22 21:59:55 dolores maestral[5770]:     raise RuntimeError("threads can only be started once")
Oct 22 21:59:55 dolores maestral[5770]: RuntimeError: threads can only be started once

# Fixed code
def __init__(self, run=True):
    self.client = MaestralApiClient()

    # periodically check for updates and refresh account info
    self.update_thread = Thread(
        name="Maestral update check",
        target=self._periodic_refresh,
        daemon=True,
    )
    self.update_thread.start()

    # monitor needs to be created before any decorators are called
    self.monitor = MaestralMonitor(self.client)
    self.sync = self.monitor.sync

    if NOTIFY_SOCKET and system_notifier:
        # notify systemd that we have successfully started
        system_notifier.notify("READY=1")

    if WATCHDOG_USEC and int(WATCHDOG_PID) == os.getpid() and system_notifier:
        # notify systemd periodically that we are still alive
        self.watchdog_thread = Thread(
            name="Maestral watchdog",
            target=self._periodic_watchdog,
            daemon=True,
        )
        self.watchdog_thread.start()

    if run:
        # if `run == False`, make sure that you manually run the setup
        # before calling `start_sync`
        if self.pending_dropbox_folder():
            self.create_dropbox_directory()
            self.set_excluded_folders()

            self.sync.last_cursor = ""
            self.sync.last_sync = 0

        self.start_sync()