Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tqdm.__repr__() crashes when disable=True #624

Closed
3 tasks done
kratsg opened this issue Oct 4, 2018 · 3 comments · Fixed by #1113
Closed
3 tasks done

tqdm.__repr__() crashes when disable=True #624

kratsg opened this issue Oct 4, 2018 · 3 comments · Fixed by #1113
Assignees
Labels
c1-quick 🕐 Complexity low p0-bug-critical ☢ Exception rasing to-fix ⌛ In progress
Projects
Milestone

Comments

@kratsg
Copy link

kratsg commented Oct 4, 2018

  • I have visited the source website, and in particular
    read the known issues
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:
>>> import tqdm, sys
>>> print(tqdm.__version__, sys.version, sys.platform)
('4.26.0', '2.7.14 (default, Mar 22 2018, 15:04:47) \n[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]', 'darwin')
>>> a = tqdm.tqdm([], disable=True)
>>> print a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kratsg/.virtualenvs/pyhf/lib/python2.7/site-packages/tqdm/_tqdm.py", line 894, in __repr__
    elapsed if elapsed is not None else self._time() - self.start_t,
AttributeError: 'tqdm' object has no attribute '_time'
>>> str(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kratsg/.virtualenvs/pyhf/lib/python2.7/site-packages/tqdm/_tqdm.py", line 894, in __repr__
    elapsed if elapsed is not None else self._time() - self.start_t,
AttributeError: 'tqdm' object has no attribute '_time'
>>> dir(a)
['__class__', '__del__', '__delattr__', '__dict__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_comparable', '_decr_instances', '_get_free_pos', '_instances', '_lock', 'clear', 'close', 'disable', 'external_write_mode', 'format_interval', 'format_meter', 'format_sizeof', 'get_lock', 'iterable', 'monitor', 'monitor_interval', 'moveto', 'n', 'pandas', 'pos', 'refresh', 'set_description', 'set_description_str', 'set_lock', 'set_postfix', 'set_postfix_str', 'status_printer', 'total', 'unpause', 'update', 'write']

Why does this occur? If disabled, then this block is evaluated during initialization (https://github.com/tqdm/tqdm/blob/master/tqdm/_tqdm.py#L763-L770) which immediately returns and therefore skips the "store the arguments" portion: https://github.com/tqdm/tqdm/blob/master/tqdm/_tqdm.py#L819-L841.

Not clear to me how this should be handled or if this is expected.

hat-tip to @matthewfeickert for finding this bug.

@matthewfeickert
Copy link

I don't think this is probably too important/helpful, but for reference the line that caused me to notice this is

https://github.com/diana-hep/pyhf/blob/fdcfb976dc5287590279b0ece7fc700b8208a337/pyhf/readxml.py#L149

though strangely enough this doesn't fail right away (c.f. cell 4 of our example Jupyter notebook which runs in Binder at the moment) — I only found this behavior when breaking pyhf.readxml.parse apart to do some debug testing.

@casperdcl casperdcl self-assigned this Oct 5, 2018
@casperdcl casperdcl added p0-bug-critical ☢ Exception rasing to-fix ⌛ In progress labels Oct 5, 2018
@cglazner
Copy link

cglazner commented Nov 6, 2018

Something similar happens when calling set_description on a tqdm_notebook with disable=True. Some of the initialization code is skipped.

>>> import sys
>>> import tqdm._tqdm_notebook
>>> print(tqdm.__version__, sys.version, sys.platform)
('4.28.1', '2.7.10 (default, Oct 23 2015, 19:19:21) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]', 'darwin')
>>> pb = tqdm._tqdm_notebook.tqdm_notebook([], disable=True)
>>> pb.set_description(desc='desc')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/cglazner/pvenv27/lib/python2.7/site-packages/tqdm/_tqdm_notebook.py", line 264, in set_description
    self.sp(desc=desc)
AttributeError: 'tqdm_notebook' object has no attribute 'sp'

@michael-koeller
Copy link

Critical bug, for two years not fixed, hm ...

We did a private monkey-patch fix, wich helped us for a while:

# check and fix for <https://github.com/tqdm/tqdm/issues/624>
if not hasattr(self.t, '_time') or getattr(self.t, '_time') is None: 
    setattr(self.t, '_time', time)

However a commit on 2020-12-24 introduced another AttributeError:

~/projects/sandbox> python3
Python 3.9.1 (default, Jan  8 2021, 17:17:43) 
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tqdm
>>> from time import time
>>> print(tqdm.__version__)
4.56.0
>>> t = tqdm.tqdm(disable=True)
>>> if not hasattr(t, '_time') or getattr(t, '_time') is None:
...     setattr(t, '_time', time)
... 
>>> t.reset()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/tqdm/std.py", line 1349, in reset
    self._ema_dn = EMA(self.smoothing)
AttributeError: 'tqdm' object has no attribute 'smoothing'

The last tagged version before this regression is: 4.54.1

@casperdcl casperdcl added this to the Non-breaking milestone Feb 9, 2021
@casperdcl casperdcl added the c1-quick 🕐 Complexity low label Feb 9, 2021
casperdcl added a commit that referenced this issue Feb 9, 2021
@casperdcl casperdcl added this to Done in Casper Feb 9, 2021
matthewfeickert added a commit to scikit-hep/pyhf that referenced this issue Feb 9, 2021
* Update tqdm to require tqdm v4.56 as minimum to get tqdm.__repr__() crash fix
   - c.f. tqdm/tqdm#624
   - Fix was released in tqdm v4.5.6.1, but minimum of v4.56 will pick this up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c1-quick 🕐 Complexity low p0-bug-critical ☢ Exception rasing to-fix ⌛ In progress
Projects
Casper
  
Done
Development

Successfully merging a pull request may close this issue.

5 participants