# Buggy code
def format_meter(
    n,
    total,
    elapsed,
    ncols=None,
    prefix="",
    ascii=False,
    unit="it",
    unit_scale=False,
    rate=None,
    bar_format=None,
    postfix=None,
    unit_divisor=1000,
):
    """
    Return a string-based progress bar given some parameters

    Parameters
    ----------
    n  : int
        Number of finished iterations.
    total  : int
        The expected total number of iterations. If meaningless (), only
        basic progress statistics are displayed (no ETA).
    elapsed  : float
        Number of seconds passed since start.
    ncols  : int, optional
        The width of the entire output message. If specified,
        dynamically resizes the progress meter to stay within this bound
        [default: None]. The fallback meter width is 10 for the progress
        bar + no limit for the iterations counter and statistics. If 0,
        will not print any meter (only stats).
    prefix  : str, optional
        Prefix message (included in total width) [default: ''].
    ascii  : bool, optional
        If not set, use unicode (smooth blocks) to fill the meter
        [default: False]. The fallback is to use ASCII characters
        (1-9 #).
    unit  : str, optional
        The iteration unit [default: 'it'].
    unit_scale  : bool, optional
        If set, the number of iterations will printed with an
        appropriate SI metric prefix (K = 10^3, M = 10^6, etc.)
        [default: False].
    rate  : float, optional
        Manual override for iteration rate.
        If [default: None], uses n/elapsed.
    bar_format  : str, optional
        Specify a custom bar string formatting. May impact performance.
        [default: '{l_bar}{bar}{r_bar}'], where l_bar is
        '{desc}{percentage:3.0f}%|' and r_bar is
        '| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}]'
        Possible vars: bar, n, n_fmt, total, total_fmt, percentage,
        rate, rate_fmt, elapsed, remaining, l_bar, r_bar, desc.
    postfix  : str, optional
        Same as prefix but will be placed at the end as additional stats.
    unit_divisor  : float, optional
        [default: 1000], ignored unless `unit_scale` is True.

    Returns
    -------
    out  : Formatted meter and stats, ready to display.
    """

    # sanity check: total
    if total and n > total:
        total = None

    format_interval = tqdm.format_interval
    elapsed_str = format_interval(elapsed)

    # if unspecified, attempt to use rate = average speed
    # (we allow manual override since predicting time is an arcane art)
    if rate is None and elapsed:
        rate = n / elapsed
    inv_rate = 1 / rate if (rate and (rate < 1)) else None
    format_sizeof = tqdm.format_sizeof
    rate_fmt = (
        (
            (
                format_sizeof(inv_rate if inv_rate else rate)
                if unit_scale
                else "{0:5.2f}".format(inv_rate if inv_rate else rate)
            )
            if rate
            else "?"
        )
        + ("s" if inv_rate else unit)
        + "/"
        + (unit if inv_rate else "s")
    )

    if unit_scale:
        n_fmt = format_sizeof(n, divisor=unit_divisor)
        total_fmt = format_sizeof(total, divisor=unit_divisor) if total else None
    else:
        n_fmt = str(n)
        total_fmt = str(total)

    # total is known: we can predict some stats
    if total:
        # fractional and percentage progress
        frac = n / total
        percentage = frac * 100

        remaining_str = format_interval((total - n) / rate) if rate else "?"

        # format the stats displayed to the left and right sides of the bar
        l_bar = (prefix if prefix else "") + "{0:3.0f}%|".format(percentage)
        r_bar = "| {0}/{1} [{2}<{3}, {4}{5}]".format(
            n_fmt,
            total_fmt,
            elapsed_str,
            remaining_str,
            rate_fmt,
            ", " + postfix if postfix else "",
        )

        if ncols == 0:
            return l_bar[:-1] + r_bar[1:]

        if bar_format:
            # Custom bar formatting
            # Populate a dict with all available progress indicators
            bar_args = {
                "n": n,
                "n_fmt": n_fmt,
                "total": total,
                "total_fmt": total_fmt,
                "percentage": percentage,
                "rate": rate if inv_rate is None else inv_rate,
                "rate_noinv": rate,
                "rate_noinv_fmt": (
                    (format_sizeof(rate) if unit_scale else "{0:5.2f}".format(rate))
                    if rate
                    else "?"
                )
                + unit
                + "/s",
                "rate_fmt": rate_fmt,
                "elapsed": elapsed_str,
                "remaining": remaining_str,
                "l_bar": l_bar,
                "r_bar": r_bar,
                "desc": prefix if prefix else "",
                "postfix": ", " + postfix if postfix else "",
                # 'bar': full_bar  # replaced by procedure below
            }

            # Interpolate supplied bar format with the dict
            if "{bar}" in bar_format:
                # Format left/right sides of the bar, and format the bar
                # later in the remaining space (avoid breaking display)
                l_bar_user, r_bar_user = bar_format.split("{bar}")
                l_bar = l_bar_user.format(**bar_args)
                r_bar = r_bar_user.format(**bar_args)
            else:
                # Else no progress bar, we can just format and return
                return bar_format.format(**bar_args)

        # Formatting progress bar
        # space available for bar's display
        N_BARS = max(1, ncols - len(l_bar) - len(r_bar)) if ncols else 10

        # format bar depending on availability of unicode/ascii chars
        if ascii:
            bar_length, frac_bar_length = divmod(int(frac * N_BARS * 10), 10)

            bar = "#" * bar_length
            frac_bar = chr(48 + frac_bar_length) if frac_bar_length else " "

        else:
            bar_length, frac_bar_length = divmod(int(frac * N_BARS * 8), 8)

            bar = _unich(0x2588) * bar_length
            frac_bar = _unich(0x2590 - frac_bar_length) if frac_bar_length else " "

        # whitespace padding
        if bar_length < N_BARS:
            full_bar = bar + frac_bar + " " * max(N_BARS - bar_length - 1, 0)
        else:
            full_bar = bar + " " * max(N_BARS - bar_length, 0)

        # Piece together the bar parts
        return l_bar + full_bar + r_bar

    # no total: no progressbar, ETA, just progress stats
    else:
        return (prefix if prefix else "") + "{0}{1} [{2}, {3}{4}]".format(
            n_fmt, unit, elapsed_str, rate_fmt, ", " + postfix if postfix else ""
        )


# Traceback (RuntimeError)
[s1758208@login04(eddie) ~]$ conda create -n test
[s1758208@login04(eddie) ~]$ conda activate test
(test) [s1758208@login04(eddie) ~]$ conda install python
Solving environment: done

## Package Plan ##

environment location: /exports/csce/eddie/ph/groups/rbm_ml/michael/myconda/envs/test

added / updated specs:
- python


The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
python-3.6.4               |       hc3d631a_3        29.1 MB
libstdcxx-ng-7.2.0         |       hdf63c60_3         2.5 MB
certifi-2018.1.18          |           py36_0         144 KB
zlib-1.2.11                |       ha838bed_2         101 KB
sqlite-3.22.0              |       h1bed415_0         1.5 MB
wheel-0.30.0               |   py36hfd4bba0_1          67 KB
openssl-1.0.2n             |       hb7f436b_0         3.4 MB
libffi-3.2.1               |       hd88cf55_4          43 KB
libgcc-ng-7.2.0            |       hdf63c60_3         6.1 MB
ncurses-6.0                |       h9df7e31_2         920 KB
tk-8.6.7                   |       hc745277_3         3.2 MB
setuptools-38.5.1          |           py36_0         525 KB
pip-9.0.1                  |           py36_5         2.2 MB
libedit-3.1                |       heed3624_0         171 KB
ca-certificates-2017.08.26 |       h1d4fec5_0         263 KB
------------------------------------------------------------
Total:        50.2 MB

The following NEW packages will be INSTALLED:

ca-certificates: 2017.08.26-h1d4fec5_0
certifi:         2018.1.18-py36_0
libedit:         3.1-heed3624_0
libffi:          3.2.1-hd88cf55_4
libgcc-ng:       7.2.0-hdf63c60_3
libstdcxx-ng:    7.2.0-hdf63c60_3
ncurses:         6.0-h9df7e31_2
openssl:         1.0.2n-hb7f436b_0
pip:             9.0.1-py36_5
python:          3.6.4-hc3d631a_3
readline:        7.0-ha6073c6_4
setuptools:      38.5.1-py36_0
sqlite:          3.22.0-h1bed415_0
tk:              8.6.7-hc745277_3
wheel:           0.30.0-py36hfd4bba0_1
xz:              5.2.3-h55aa19d_2
zlib:            1.2.11-ha838bed_2

Proceed ([y]/n)? y


Downloading and Extracting Packages
python 3.6.4: ########################################################## | 100%
libstdcxx-ng 7.2.0: #################################################### | 100%
certifi 2018.1.18: ##################################################### | 100%

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

Traceback (most recent call last):
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/exceptions.py", line 789, in __call__
return func(*args, **kwargs)
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/cli/main.py", line 78, in _main
exit_code = do_call(args, p)
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/cli/conda_argparse.py", line 77, in do_call
exit_code = getattr(module, func_name)(args, parser)
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/cli/main_install.py", line 11, in execute
install(args, parser, 'install')
File "/home/s1758208/miniconda3/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/s1758208/miniconda3/lib/python3.6/site-packages/conda/cli/install.py", line 281, in handle_txn
progressive_fetch_extract.execute()
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/core/package_cache.py", line 584, in execute
exc = self._execute_actions(prec_or_spec, prec_actions)
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/core/package_cache.py", line 599, in _execute_actions
progress_bar = ProgressBar(desc, not context.verbosity and not context.quiet, context.json)
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/common/io.py", line 390, in __init__
self.pbar = tqdm(desc=description, bar_format=bar_format, ascii=True, total=1)
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/_vendor/tqdm/_tqdm.py", line 388, in __new__
cls.monitor = TMonitor(cls, cls.monitor_interval)
File "/home/s1758208/miniconda3/lib/python3.6/site-packages/conda/_vendor/tqdm/_tqdm.py", line 83, in __init__
self.start()
File "/home/s1758208/miniconda3/lib/python3.6/threading.py", line 846, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread

# Fixed code
def format_meter(
    n,
    total,
    elapsed,
    ncols=None,
    prefix="",
    ascii=False,
    unit="it",
    unit_scale=False,
    rate=None,
    bar_format=None,
    postfix=None,
    unit_divisor=1000,
):
    """
    Return a string-based progress bar given some parameters
    Parameters
    ----------
    n  : int
        Number of finished iterations.
    total  : int
        The expected total number of iterations. If meaningless (), only
        basic progress statistics are displayed (no ETA).
    elapsed  : float
        Number of seconds passed since start.
    ncols  : int, optional
        The width of the entire output message. If specified,
        dynamically resizes the progress meter to stay within this bound
        [default: None]. The fallback meter width is 10 for the progress
        bar + no limit for the iterations counter and statistics. If 0,
        will not print any meter (only stats).
    prefix  : str, optional
        Prefix message (included in total width) [default: ''].
        Use as {desc} in bar_format string.
    ascii  : bool, optional
        If not set, use unicode (smooth blocks) to fill the meter
        [default: False]. The fallback is to use ASCII characters
        (1-9 #).
    unit  : str, optional
        The iteration unit [default: 'it'].
    unit_scale  : bool or int or float, optional
        If 1 or True, the number of iterations will be printed with an
        appropriate SI metric prefix (k = 10^3, M = 10^6, etc.)
        [default: False]. If any other non-zero number, will scale
        `total` and `n`.
    rate  : float, optional
        Manual override for iteration rate.
        If [default: None], uses n/elapsed.
    bar_format  : str, optional
        Specify a custom bar string formatting. May impact performance.
        [default: '{l_bar}{bar}{r_bar}'], where
        l_bar='{desc}: {percentage:3.0f}%|' and
        r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
          '{rate_fmt}{postfix}]'
        Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
          percentage, rate, rate_fmt, rate_noinv, rate_noinv_fmt,
          rate_inv, rate_inv_fmt, elapsed, remaining, desc, postfix.
        Note that a trailing ": " is automatically removed after {desc}
        if the latter is empty.
    postfix  : *, optional
        Similar to `prefix`, but placed at the end
        (e.g. for additional stats).
        Note: postfix is usually a string (not a dict) for this method,
        and will if possible be set to postfix = ', ' + postfix.
        However other types are supported (#382).
    unit_divisor  : float, optional
        [default: 1000], ignored unless `unit_scale` is True.
    Returns
    -------
    out  : Formatted meter and stats, ready to display.
    """

    # sanity check: total
    if total and n > total:
        total = None

    # apply custom scale if necessary
    if unit_scale and unit_scale not in (True, 1):
        total *= unit_scale
        n *= unit_scale
        unit_scale = False

    format_interval = tqdm.format_interval
    elapsed_str = format_interval(elapsed)

    # if unspecified, attempt to use rate = average speed
    # (we allow manual override since predicting time is an arcane art)
    if rate is None and elapsed:
        rate = n / elapsed
    inv_rate = 1 / rate if rate else None
    format_sizeof = tqdm.format_sizeof
    rate_noinv_fmt = (
        (
            (format_sizeof(rate) if unit_scale else "{0:5.2f}".format(rate))
            if rate
            else "?"
        )
        + unit
        + "/s"
    )
    rate_inv_fmt = (
        (
            (format_sizeof(inv_rate) if unit_scale else "{0:5.2f}".format(inv_rate))
            if inv_rate
            else "?"
        )
        + "s/"
        + unit
    )
    rate_fmt = rate_inv_fmt if inv_rate and inv_rate > 1 else rate_noinv_fmt

    if unit_scale:
        n_fmt = format_sizeof(n, divisor=unit_divisor)
        total_fmt = format_sizeof(total, divisor=unit_divisor) if total else None
    else:
        n_fmt = str(n)
        total_fmt = str(total)

    try:
        postfix = ", " + postfix if postfix else ""
    except TypeError:
        pass

    # total is known: we can predict some stats
    if total:
        # fractional and percentage progress
        frac = n / total
        percentage = frac * 100

        remaining_str = format_interval((total - n) / rate) if rate else "?"

        # format the stats displayed to the left and right sides of the bar
        if prefix:
            # old prefix setup work around
            bool_prefix_colon_already = prefix[-2:] == ": "
            l_bar = prefix if bool_prefix_colon_already else prefix + ": "
        else:
            l_bar = ""
        l_bar += "{0:3.0f}%|".format(percentage)
        r_bar = "| {0}/{1} [{2}<{3}, {4}{5}]".format(
            n_fmt, total_fmt, elapsed_str, remaining_str, rate_fmt, postfix
        )

        if ncols == 0:
            return l_bar[:-1] + r_bar[1:]

        if bar_format:
            # Custom bar formatting
            # Populate a dict with all available progress indicators
            bar_args = {
                "n": n,
                "n_fmt": n_fmt,
                "total": total,
                "total_fmt": total_fmt,
                "percentage": percentage,
                "rate": inv_rate if inv_rate and inv_rate > 1 else rate,
                "rate_fmt": rate_fmt,
                "rate_noinv": rate,
                "rate_noinv_fmt": rate_noinv_fmt,
                "rate_inv": inv_rate,
                "rate_inv_fmt": rate_inv_fmt,
                "elapsed": elapsed_str,
                "remaining": remaining_str,
                "l_bar": l_bar,
                "r_bar": r_bar,
                "desc": prefix or "",
                "postfix": postfix,
                # 'bar': full_bar  # replaced by procedure below
            }

            # auto-remove colon for empty `desc`
            if not prefix:
                bar_format = bar_format.replace("{desc}: ", "")

            # Interpolate supplied bar format with the dict
            if "{bar}" in bar_format:
                # Format left/right sides of the bar, and format the bar
                # later in the remaining space (avoid breaking display)
                l_bar_user, r_bar_user = bar_format.split("{bar}")
                l_bar = l_bar_user.format(**bar_args)
                r_bar = r_bar_user.format(**bar_args)
            else:
                # Else no progress bar, we can just format and return
                return bar_format.format(**bar_args)

        # Formatting progress bar
        # space available for bar's display
        N_BARS = max(1, ncols - len(l_bar) - len(r_bar)) if ncols else 10

        # format bar depending on availability of unicode/ascii chars
        if ascii:
            bar_length, frac_bar_length = divmod(int(frac * N_BARS * 10), 10)

            bar = "#" * bar_length
            frac_bar = chr(48 + frac_bar_length) if frac_bar_length else " "

        else:
            bar_length, frac_bar_length = divmod(int(frac * N_BARS * 8), 8)

            bar = _unich(0x2588) * bar_length
            frac_bar = _unich(0x2590 - frac_bar_length) if frac_bar_length else " "

        # whitespace padding
        if bar_length < N_BARS:
            full_bar = bar + frac_bar + " " * max(N_BARS - bar_length - 1, 0)
        else:
            full_bar = bar + " " * max(N_BARS - bar_length, 0)

        # Piece together the bar parts
        return l_bar + full_bar + r_bar

    # no total: no progressbar, ETA, just progress stats
    else:
        return ((prefix + ": ") if prefix else "") + "{0}{1} [{2}, {3}{4}]".format(
            n_fmt, unit, elapsed_str, rate_fmt, postfix
        )