**Apache Airflow version**: 2.0.0a2

As of #9363, the `tasks run` command attempts to restore the root logger handlers to the previous state after running the task with the handlers all replaced by those from the `airflow.tasks` logger.

However, because no actual *copy* is created of the root handlers list, what you effectively end up with is either an empty list of handlers and nothing is restored. To make matters worse, the block ends with a `logging.shutdown()` call, which completely closes and releases all handlers.

So, either the code to 'restore' can just be removed, or a proper copy needs to be made and the `logging.shutdown()` call needs to be removed from the command. `logging.shutdown` is going to be called when the interpreter exits, anyway.

In detail, this is the code section:

https://github.com/apache/airflow/blob/bec9f3b29fd42ecd1beae3db75784b9a726caf15/airflow/cli/commands/task_command.py#L194-L222

The first problem here is that `root_logger_handlers = root_logger.handlers` merely creates a reference to the logger `handlers` list. The `root_logger.removeHandler(handler)` in a loop further on remove the handlers from that same list as you iterate, and this causes it to [only remove *every second handler*](https://sopython.com/canon/95/removing-items-from-a-list-while-iterating-over-the-list/). Luckily, this was never a problem because in the standard configuration there is only a single handler on the root. If there are more, there is a bigger problem further down.

Continuing on, the next loop, adding handlers from `airflow_logger_handlers`, causes those same handlers to show up in the `root_logger_handlers` reference, but those very same handlers are removed again in a second loop over the same `airflow_logger_handlers` list.

So when you hit the final `for handler in root_logger_handlers: root_logger.addHandler(handler)` loop, either `root_logger_handlers` is an empty list (no handlers added), or, if you started with more than one root handler and every second handler was left in place, you now are adding handlers to the list that are already in the list.  The `Logger.addHandler()` method uses `self.handler.append()`, appending to a list you are iterating over, and so you have an infinite loop on your hands.

Either just remove all handlers from the root logger (taking care to loop over the list in reverse, e.g. `for h in reversed(root_logger.handlers): root_logger.removeHandler(h)`), or create proper copy of the list with `root_logger_handlers = root_logger.handlers[:]`. The `logging.shutdown()` call has to be removed then too.




tests/cli/commands/test_task_command.py
"""
        Test that we can run naive (non-localized) task instances
        """
        naive_date = datetime(2016, 1, 1)
        dag_id = 'test_run_ignores_all_dependencies'
        dag = self.dagbag.get_dag('test_run_ignores_all_dependencies')
        task0_id = 'test_run_dependent_task'
        args0 = [
            'tasks',
            'run',
            '--ignore-all-dependencies',
            '--local',
            dag_id,
            task0_id,
            naive_date.isoformat(),
        ]
        task_command.task_run(self.parser.parse_args(args0), dag=dag)
        mock_local_job.assert_called_once_with(
            task_instance=mock.ANY,
            mark_success=False,
            ignore_all_deps=True,
            ignore_depends_on_past=False,
            ignore_task_deps=False,
            ignore_ti_state=False,
            pickle_id=None,
            pool=None,
        )
    def test_cli_test(self):