Skip to content

Exception thrown in destructor during python shutdown #1198

@t-vi

Description

@t-vi

When there is a tqdm std bar in existance and Python shuts down, it is possible to hit the following:
In it's __del__ method and in the call to format_dict, you hit this line

tqdm/tqdm/utils.py

Lines 275 to 280 in c1ec3b1

try:
from array import array
from fcntl import ioctl
from termios import TIOCGWINSZ
except ImportError:
return None

because the shutdown causes the import to fail at some point and apparently del is later than that point.

But this returns only None, when it should return two elements, leading to an unable to unpack none exception.
I would suggest to return None, None like in the error case a few lines down.

tqdm/tqdm/utils.py

Lines 286 to 289 in c1ec3b1

try:
return [int(os.environ[i]) - 1 for i in ("COLUMNS", "LINES")]
except (KeyError, ValueError):
return None, None

Of course, my favourite fix would be to not import stuff within a function, but hey, what do I know.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions