Skip to content

Commit

Permalink
Update decorators.py
Browse files Browse the repository at this point in the history
  • Loading branch information
alanyee committed Sep 30, 2020
1 parent 8f1c189 commit cfafa35
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions animation/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import time
import signal
from functools import wraps

from . import animations


Expand All @@ -28,9 +29,8 @@ def end_wait_threads(signal, frame):
sys.stdout.write('\n')
return

for sig in ['SIGINT', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'SIGTERM']:
if hasattr(signal, sig):
signal.signal(getattr(signal, sig), end_wait_threads)
for sig in (signal.SIGINT, signal.SIGUSR1, signal.SIGUSR2, signal.SIGTERM):
signal.signal(sig, end_wait_threads)


# animation objects
Expand Down Expand Up @@ -74,9 +74,7 @@ def _animate(self):
self._count = 0

sys.stdout.write(self.text)
while True:
if self._count < 0:
break
while self._count >= 0:
if self._count != 0:
sys.stdout.write(self.reverser)
sys.stdout.write(self._data[self._count % len(self._data)])
Expand All @@ -86,17 +84,13 @@ def _animate(self):
return

def start(self):
"""
Start animation thread.
"""
"""Start animation thread."""
self.thread = threading.Thread(target=self._animate)
self.thread.start()
return

def stop(self):
"""
Stop animation thread.
"""
"""Stop animation thread."""
time.sleep(self.speed)
self._count = -9999
sys.stdout.write(self.reverser + '\r\033[K')
Expand Down

0 comments on commit cfafa35

Please sign in to comment.