Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting both python 2 and python 3 + fixed "threads can only be started once" issue #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions nyanbar/nyanbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ def __init__(self, interval=100, tasks=0, visible=True, audiofile=None):
self._audiofile = audiofile
self._audiopid = None
self.setDaemon(True)
self._started = threading.Event()
self._running = False
self._showing = visible
if visible:
self._running = True
self.start()

def __enter__(self):
Expand All @@ -121,7 +122,7 @@ def __exit__(self, *args):
self.finish()

def show(self, visible=True):
if not self._started.is_set():
if not self._running:
self.start()
self._showing = visible

Expand All @@ -133,7 +134,7 @@ def play(self):
self._audiopid = subprocess.Popen(args).pid

def run(self):
self._started.set()
self._running = True
self.play()
while not self._finished:
self._draw(self._amount)
Expand Down