# Buggy code
def execute_command(self, options):
    """
    Handles the 'execute' CLI command.

    If there is already a task queue running in this process, adds the execution to the queue.
    If FlexGet is being invoked with this command, starts up a task queue and runs the execution.

    Fires events:

    * manager.execute.started
    * manager.execute.completed

    :param options: argparse options
    """
    fire_event("manager.execute.started", self, options)
    if self.task_queue.is_alive():
        if len(self.task_queue):
            log.verbose("There is a task already running, execution queued.")
        finished_events = self.execute(
            options,
            output=logger.get_capture_stream(),
            loglevel=logger.get_capture_loglevel(),
        )
        if not options.cron:
            # Wait until execution of all tasks has finished
            for _, _, event in finished_events:
                event.wait()
    else:
        self.task_queue.start()
        self.ipc_server.start()
        self.execute(options)
        self.shutdown(finish_queue=True)
        self.task_queue.wait()
    fire_event("manager.execute.completed", self, options)


# Traceback (RuntimeError)
There is a FlexGet process already running for this config, sending execution there.
Traceback (most recent call last):
File "/opt/bin/flexget", line 11, in <module>
sys.exit(main())
File "/opt/lib/python3.5/site-packages/flexget/__init__.py", line 42, in main
manager.start()
File "/opt/lib/python3.5/site-packages/flexget/manager.py", line 294, in start
client.handle_cli(self.args)
File "/opt/lib/python3.5/site-packages/rpyc/core/netref.py", line 196, in __call__
return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
File "/opt/lib/python3.5/site-packages/rpyc/core/netref.py", line 71, in syncreq
return conn.sync_request(handler, oid, *args)
File "/opt/lib/python3.5/site-packages/rpyc/core/protocol.py", line 441, in sync_request
raise obj
RuntimeError: threads can only be started once

========= Remote Traceback (1) =========
Traceback (most recent call last):
File "/opt/lib/python3.5/site-packages/rpyc/core/protocol.py", line 305, in _dispatch_request
res = self._HANDLERS[handler](self, *args)
File "/opt/lib/python3.5/site-packages/rpyc/core/protocol.py", line 535, in _handle_call
return self._local_objects[oid](*args, **dict(kwargs))
File "/opt/lib/python3.5/site-packages/flexget/ipc.py", line 80, in exposed_handle_cli
self.manager.handle_cli(options)
File "/opt/lib/python3.5/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/opt/lib/python3.5/site-packages/flexget/logger.py", line 88, in capture_output
yield
File "/opt/lib/python3.5/site-packages/flexget/ipc.py", line 80, in exposed_handle_cli
self.manager.handle_cli(options)
File "/opt/lib/python3.5/site-packages/flexget/manager.py", line 333, in handle_cli
self.execute_command(command_options)
File "/opt/lib/python3.5/site-packages/flexget/manager.py", line 365, in execute_command
self.task_queue.start()
File "/opt/lib/python3.5/site-packages/flexget/task_queue.py", line 35, in start
self._thread.start()
File "/opt/lib/python3.5/threading.py", line 840, in start
raise RuntimeError("threads can only be started once")
RuntimeError: threads can only be started once

# Fixed code
def execute_command(self, options):
    """
    Handles the 'execute' CLI command.

    If there is already a task queue running in this process, adds the execution to the queue.
    If FlexGet is being invoked with this command, starts up a task queue and runs the execution.

    Fires events:

    * manager.execute.started
    * manager.execute.completed

    :param options: argparse options
    """
    fire_event("manager.execute.started", self, options)
    if self.task_queue.is_alive() or self.is_daemon:
        if not self.task_queue.is_alive():
            log.error(
                "Task queue has died unexpectedly. Restarting it. Please open an issue on Github and include"
                " any previous error logs."
            )
            self.task_queue = TaskQueue()
            self.task_queue.start()
        if len(self.task_queue):
            log.verbose("There is a task already running, execution queued.")
        finished_events = self.execute(
            options,
            output=logger.get_capture_stream(),
            loglevel=logger.get_capture_loglevel(),
        )
        if not options.cron:
            # Wait until execution of all tasks has finished
            for _, _, event in finished_events:
                event.wait()
    else:
        self.task_queue.start()
        self.ipc_server.start()
        self.execute(options)
        self.shutdown(finish_queue=True)
        self.task_queue.wait()
    fire_event("manager.execute.completed", self, options)