atexit.unregister does not exist in Python 2.7

Implement this with __del__ instead
This commit is contained in:
Georgios Verigakis
2020-07-20 13:32:47 +03:00
parent 12e46ed702
commit 64671e1ceb

View File

@@ -14,7 +14,6 @@
from __future__ import division, print_function from __future__ import division, print_function
import atexit
from collections import deque from collections import deque
from datetime import timedelta from datetime import timedelta
from math import ceil from math import ceil
@@ -48,14 +47,19 @@ class Infinite(object):
setattr(self, key, val) setattr(self, key, val)
self._max_width = 0 self._max_width = 0
self._hidden_cursor = False
self.message = message self.message = message
if self.file and self.is_tty(): if self.file and self.is_tty():
if self.hide_cursor: if self.hide_cursor:
print(HIDE_CURSOR, end='', file=self.file) print(HIDE_CURSOR, end='', file=self.file)
atexit.register(self.finish) self._hidden_cursor = True
self.writeln('') self.writeln('')
def __del__(self):
if self._hidden_cursor:
print(SHOW_CURSOR, end='', file=self.file)
def __getitem__(self, key): def __getitem__(self, key):
if key.startswith('_'): if key.startswith('_'):
return None return None
@@ -100,9 +104,9 @@ class Infinite(object):
def finish(self): def finish(self):
if self.file and self.is_tty(): if self.file and self.is_tty():
print(file=self.file) print(file=self.file)
if self.hide_cursor: if self._hidden_cursor:
print(SHOW_CURSOR, end='', file=self.file) print(SHOW_CURSOR, end='', file=self.file)
atexit.unregister(self.finish) self._hidden_cursor = False
def is_tty(self): def is_tty(self):
try: try: