# Buggy code
def prepare(self):
    if self._prepared:
        return

    self.transaction_context = {}

    with spinner(
        "Preparing transaction",
        not context.verbosity and not context.quiet,
        context.json,
    ):
        for stp in itervalues(self.prefix_setups):
            grps = self._prepare(
                self.transaction_context,
                stp.target_prefix,
                stp.unlink_precs,
                stp.link_precs,
                stp.remove_specs,
                stp.update_specs,
            )
            self.prefix_action_groups[stp.target_prefix] = PrefixActionGroup(*grps)

    self._prepared = True


# 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 prepare(self):
    if self._prepared:
        return

    self.transaction_context = {}

    with Spinner(
        "Preparing transaction",
        not context.verbosity and not context.quiet,
        context.json,
    ):
        for stp in itervalues(self.prefix_setups):
            grps = self._prepare(
                self.transaction_context,
                stp.target_prefix,
                stp.unlink_precs,
                stp.link_precs,
                stp.remove_specs,
                stp.update_specs,
            )
            self.prefix_action_groups[stp.target_prefix] = PrefixActionGroup(*grps)

    self._prepared = True