Skip to content

Commit

Permalink
atexit.unregister does not exist in Python 2.7
Browse files Browse the repository at this point in the history
Implement this with __del__ instead
  • Loading branch information
verigak committed Jul 20, 2020
1 parent 12e46ed commit 64671e1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions progress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from __future__ import division, print_function

import atexit
from collections import deque
from datetime import timedelta
from math import ceil
Expand Down Expand Up @@ -48,14 +47,19 @@ def __init__(self, message='', **kwargs):
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
Expand Down Expand Up @@ -100,9 +104,9 @@ def writeln(self, line):
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:
Expand Down

0 comments on commit 64671e1

Please sign in to comment.