# Buggy code
def __iter__(self):
    """Backward-compatibility to use: for x in tqdm(iterable)"""

    # Inlining instance variables as locals (speed optimisation)
    iterable = self.iterable

    # If the bar is disabled, then just walk the iterable
    # (note: keep this check outside the loop for performance)
    if self.disable:
        for obj in iterable:
            yield obj
    else:
        ncols = self.ncols
        mininterval = self.mininterval
        maxinterval = self.maxinterval
        miniters = self.miniters
        dynamic_miniters = self.dynamic_miniters
        unit = self.unit
        unit_scale = self.unit_scale
        unit_divisor = self.unit_divisor
        ascii = self.ascii
        start_t = self.start_t
        last_print_t = self.last_print_t
        last_print_n = self.last_print_n
        n = self.n
        dynamic_ncols = self.dynamic_ncols
        smoothing = self.smoothing
        avg_time = self.avg_time
        bar_format = self.bar_format
        _time = self._time
        format_meter = self.format_meter

        try:
            sp = self.sp
        except AttributeError:
            raise TqdmDeprecationWarning(
                """\
Please use `tqdm_gui(...)` instead of `tqdm(..., gui=True)`
""",
                fp_write=getattr(self.fp, "write", sys.stderr.write),
            )

        for obj in iterable:
            yield obj
            # Update and print the progressbar.
            # Note: does not call self.update(1) for speed optimisation.
            n += 1
            # check the counter first (avoid calls to time())
            if n - last_print_n >= self.miniters:
                miniters = self.miniters  # watch monitoring thread changes
                delta_t = _time() - last_print_t
                if delta_t >= mininterval:
                    cur_t = _time()
                    delta_it = n - last_print_n
                    elapsed = cur_t - start_t  # optimised if in inner loop
                    # EMA (not just overall average)
                    if smoothing and delta_t and delta_it:
                        avg_time = (
                            delta_t / delta_it
                            if avg_time is None
                            else smoothing * delta_t / delta_it
                            + (1 - smoothing) * avg_time
                        )

                    if self.pos:
                        self.moveto(self.pos)

                    # Printing the bar's update
                    sp(
                        format_meter(
                            n,
                            self.total,
                            elapsed,
                            (dynamic_ncols(self.fp) if dynamic_ncols else ncols),
                            self.desc,
                            ascii,
                            unit,
                            unit_scale,
                            1 / avg_time if avg_time else None,
                            bar_format,
                            self.postfix,
                            unit_divisor,
                        )
                    )

                    if self.pos:
                        self.moveto(-self.pos)

                    # If no `miniters` was specified, adjust automatically
                    # to the max iteration rate seen so far between 2 prints
                    if dynamic_miniters:
                        if maxinterval and delta_t >= maxinterval:
                            # Adjust miniters to time interval by rule of 3
                            if mininterval:
                                # Set miniters to correspond to mininterval
                                miniters = delta_it * mininterval / delta_t
                            else:
                                # Set miniters to correspond to maxinterval
                                miniters = delta_it * maxinterval / delta_t
                        elif smoothing:
                            # EMA-weight miniters to converge
                            # towards the timeframe of mininterval
                            miniters = (
                                smoothing
                                * delta_it
                                * (
                                    mininterval / delta_t
                                    if mininterval and delta_t
                                    else 1
                                )
                                + (1 - smoothing) * miniters
                            )
                        else:
                            # Maximum nb of iterations between 2 prints
                            miniters = max(miniters, delta_it)

                    # Store old values for next call
                    self.n = self.last_print_n = last_print_n = n
                    self.last_print_t = last_print_t = cur_t
                    self.miniters = miniters

        # Closing the progress bar.
        # Update some internal variables for close().
        self.last_print_n = last_print_n
        self.n = n
        self.miniters = miniters
        self.close()


# 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 __iter__(self):
    """Backward-compatibility to use: for x in tqdm(iterable)"""

    # Inlining instance variables as locals (speed optimisation)
    iterable = self.iterable

    # If the bar is disabled, then just walk the iterable
    # (note: keep this check outside the loop for performance)
    if self.disable:
        for obj in iterable:
            yield obj
    else:
        mininterval = self.mininterval
        maxinterval = self.maxinterval
        miniters = self.miniters
        dynamic_miniters = self.dynamic_miniters
        last_print_t = self.last_print_t
        last_print_n = self.last_print_n
        n = self.n
        smoothing = self.smoothing
        avg_time = self.avg_time
        _time = self._time

        try:
            sp = self.sp
        except AttributeError:
            raise TqdmDeprecationWarning(
                """\
Please use `tqdm_gui(...)` instead of `tqdm(..., gui=True)`
""",
                fp_write=getattr(self.fp, "write", sys.stderr.write),
            )

        for obj in iterable:
            yield obj
            # Update and possibly print the progressbar.
            # Note: does not call self.update(1) for speed optimisation.
            n += 1
            # check counter first to avoid calls to time()
            if n - last_print_n >= self.miniters:
                miniters = self.miniters  # watch monitoring thread changes
                delta_t = _time() - last_print_t
                if delta_t >= mininterval:
                    cur_t = _time()
                    delta_it = n - last_print_n
                    # EMA (not just overall average)
                    if smoothing and delta_t and delta_it:
                        avg_time = (
                            delta_t / delta_it
                            if avg_time is None
                            else smoothing * delta_t / delta_it
                            + (1 - smoothing) * avg_time
                        )

                    self.n = n
                    with self._lock:
                        if self.pos:
                            self.moveto(abs(self.pos))
                        # Print bar update
                        sp(self.__repr__())
                        if self.pos:
                            self.moveto(-abs(self.pos))

                    # If no `miniters` was specified, adjust automatically
                    # to the max iteration rate seen so far between 2 prints
                    if dynamic_miniters:
                        if maxinterval and delta_t >= maxinterval:
                            # Adjust miniters to time interval by rule of 3
                            if mininterval:
                                # Set miniters to correspond to mininterval
                                miniters = delta_it * mininterval / delta_t
                            else:
                                # Set miniters to correspond to maxinterval
                                miniters = delta_it * maxinterval / delta_t
                        elif smoothing:
                            # EMA-weight miniters to converge
                            # towards the timeframe of mininterval
                            miniters = (
                                smoothing
                                * delta_it
                                * (
                                    mininterval / delta_t
                                    if mininterval and delta_t
                                    else 1
                                )
                                + (1 - smoothing) * miniters
                            )
                        else:
                            # Maximum nb of iterations between 2 prints
                            miniters = max(miniters, delta_it)

                    # Store old values for next call
                    self.n = self.last_print_n = last_print_n = n
                    self.last_print_t = last_print_t = cur_t
                    self.miniters = miniters

        # Closing the progress bar.
        # Update some internal variables for close().
        self.last_print_n = last_print_n
        self.n = n
        self.miniters = miniters
        self.close()