From 5599bb7fa30bf5d9d765e9af41fd9b5f89fc73eb Mon Sep 17 00:00:00 2001 From: Konstantin Merenkov Date: Thu, 24 Apr 2014 10:11:20 +0400 Subject: [PATCH] Supporting both python 2 and python 3 + fixed "threads can only be started once" issue - _started is used by Thread class in python 3, so I renamed it to _running (in python 2 Thread used __started, not _started) - In constructor, right after calling Thread.start method, setting _running to True, so the next call to Thread.show wouldn't raise "threads can only be started once" error --- nyanbar/nyanbar.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nyanbar/nyanbar.py b/nyanbar/nyanbar.py index cdcea28..4283049 100644 --- a/nyanbar/nyanbar.py +++ b/nyanbar/nyanbar.py @@ -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): @@ -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 @@ -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)