mirror of
https://github.com/verigak/progress.git
synced 2025-12-08 19:33:24 +00:00
atexit.unregister does not exist in Python 2.7
Implement this with __del__ instead
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user