From 64671e1ceb5ea5a1f37ff4236476a7cab92a779b Mon Sep 17 00:00:00 2001 From: Georgios Verigakis Date: Mon, 20 Jul 2020 13:32:47 +0300 Subject: [PATCH] atexit.unregister does not exist in Python 2.7 Implement this with __del__ instead --- progress/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/progress/__init__.py b/progress/__init__.py index 0e0560c..18f5d0f 100644 --- a/progress/__init__.py +++ b/progress/__init__.py @@ -14,7 +14,6 @@ from __future__ import division, print_function -import atexit from collections import deque from datetime import timedelta from math import ceil @@ -48,14 +47,19 @@ class Infinite(object): setattr(self, key, val) self._max_width = 0 + self._hidden_cursor = False self.message = message if self.file and self.is_tty(): if self.hide_cursor: print(HIDE_CURSOR, end='', file=self.file) - atexit.register(self.finish) + self._hidden_cursor = True self.writeln('') + def __del__(self): + if self._hidden_cursor: + print(SHOW_CURSOR, end='', file=self.file) + def __getitem__(self, key): if key.startswith('_'): return None @@ -100,9 +104,9 @@ class Infinite(object): def finish(self): if self.file and self.is_tty(): print(file=self.file) - if self.hide_cursor: + if self._hidden_cursor: print(SHOW_CURSOR, end='', file=self.file) - atexit.unregister(self.finish) + self._hidden_cursor = False def is_tty(self): try: