# Buggy code
def _execute(cls, all_action_groups):
    with signal_handler(conda_signal_handler), time_recorder("unlink_link_execute"):
        pkg_idx = 0
        try:
            with spinner(
                "Executing transaction",
                not context.verbosity and not context.quiet,
                context.json,
            ):
                for pkg_idx, axngroup in enumerate(all_action_groups):
                    cls._execute_actions(pkg_idx, axngroup)
        except CondaMultiError as e:
            action, is_unlink = (None, axngroup.type == "unlink")
            prec = axngroup.pkg_data

            log.error(
                "An error occurred while %s package '%s'.\n"
                "%r\n"
                "Attempting to roll back.\n",
                "uninstalling" if is_unlink else "installing",
                prec and prec.dist_str(),
                e.errors[0],
            )

            # reverse all executed packages except the one that failed
            rollback_excs = []
            if context.rollback_enabled:
                with spinner(
                    "Rolling back transaction",
                    not context.verbosity and not context.quiet,
                    context.json,
                ):
                    failed_pkg_idx = pkg_idx
                    reverse_actions = reversed(
                        tuple(enumerate(take(failed_pkg_idx, all_action_groups)))
                    )
                    for pkg_idx, axngroup in reverse_actions:
                        excs = cls._reverse_actions(pkg_idx, axngroup)
                        rollback_excs.extend(excs)

            raise CondaMultiError(
                tuple(
                    concatv(
                        (e.errors if isinstance(e, CondaMultiError) else (e,)),
                        rollback_excs,
                    )
                )
            )
        else:
            for axngroup in all_action_groups:
                for action in axngroup.actions:
                    action.cleanup()


# Traceback (BrokenPipeError)
error: BrokenPipeError(32, 'Broken pipe')
command: /home/ubuntu/anaconda3/envs/tensorflow_p36/bin/conda install -p /home/ubuntu/anaconda3/envs/tensorflow_p36 tensorflow-gpu -y
user_agent: conda/4.4.4 requests/2.18.4 CPython/3.6.3 Linux/4.4.0-1044-aws ubuntu/16.04 glibc/2.23
_messageid: -9223372036845075603
_messagetime: 1514219033248 / 2017-12-25 10:23:53

Traceback (most recent call last):
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/exceptions.py", line 724, in __call__
return func(*args, **kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/cli/main.py", line 78, in _main
exit_code = do_call(args, p)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/cli/conda_argparse.py", line 75, in do_call
exit_code = getattr(module, func_name)(args, parser)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/cli/main_install.py", line 11, in execute
install(args, parser, 'install')
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/cli/install.py", line 255, in install
handle_txn(progressive_fetch_extract, unlink_link_transaction, prefix, args, newenv)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/cli/install.py", line 281, in handle_txn
progressive_fetch_extract.execute()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/core/package_cache.py", line 575, in execute
exc = self._execute_actions(prec_or_spec, prec_actions)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/core/package_cache.py", line 590, in _execute_actions
progress_bar = ProgressBar(desc, not context.verbosity and not context.quiet, context.json)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/common/io.py", line 365, in __init__
self.pbar = tqdm(desc=description, bar_format=bar_format, ascii=True, total=1)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/_vendor/tqdm/_tqdm.py", line 767, in __init__
self.postfix, unit_divisor))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/_vendor/tqdm/_tqdm.py", line 201, in print_status
fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0)))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/conda/_vendor/tqdm/_tqdm.py", line 195, in fp_write
fp_flush()
BrokenPipeError: [Errno 32] Broken pipe

# Fixed code
def _execute(cls, all_action_groups):
    with signal_handler(conda_signal_handler), time_recorder("unlink_link_execute"):
        pkg_idx = 0
        try:
            with Spinner(
                "Executing transaction",
                not context.verbosity and not context.quiet,
                context.json,
            ):
                for pkg_idx, axngroup in enumerate(all_action_groups):
                    cls._execute_actions(pkg_idx, axngroup)
        except CondaMultiError as e:
            action, is_unlink = (None, axngroup.type == "unlink")
            prec = axngroup.pkg_data

            log.error(
                "An error occurred while %s package '%s'.\n"
                "%r\n"
                "Attempting to roll back.\n",
                "uninstalling" if is_unlink else "installing",
                prec and prec.dist_str(),
                e.errors[0],
            )

            # reverse all executed packages except the one that failed
            rollback_excs = []
            if context.rollback_enabled:
                with Spinner(
                    "Rolling back transaction",
                    not context.verbosity and not context.quiet,
                    context.json,
                ):
                    failed_pkg_idx = pkg_idx
                    reverse_actions = reversed(
                        tuple(enumerate(take(failed_pkg_idx, all_action_groups)))
                    )
                    for pkg_idx, axngroup in reverse_actions:
                        excs = cls._reverse_actions(pkg_idx, axngroup)
                        rollback_excs.extend(excs)

            raise CondaMultiError(
                tuple(
                    concatv(
                        (e.errors if isinstance(e, CondaMultiError) else (e,)),
                        rollback_excs,
                    )
                )
            )
        else:
            for axngroup in all_action_groups:
                for action in axngroup.actions:
                    action.cleanup()