mirror of
https://github.com/ankitects/anki.git
synced 2025-11-12 07:37:11 -05:00
use devnull instead of reader thread; fix cleanup code
thanks to robert siemer for the devnull idea
This commit is contained in:
parent
0a279f6a26
commit
9bcfc9e1d4
1 changed files with 4 additions and 19 deletions
|
|
@ -78,19 +78,6 @@ mplayerReader = None
|
||||||
mplayerEvt = threading.Event()
|
mplayerEvt = threading.Event()
|
||||||
mplayerClear = False
|
mplayerClear = False
|
||||||
|
|
||||||
# fixme from robert: can we do away with this with stderr=file(os.devnull,
|
|
||||||
# 'w') in the popen call?
|
|
||||||
class MplayerReader(threading.Thread):
|
|
||||||
"Read any debugging info to prevent mplayer from blocking."
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
while 1:
|
|
||||||
mplayerEvt.wait()
|
|
||||||
try:
|
|
||||||
mplayerManager.mplayer.stdout.read()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class MplayerMonitor(threading.Thread):
|
class MplayerMonitor(threading.Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
@ -144,9 +131,10 @@ class MplayerMonitor(threading.Thread):
|
||||||
def startProcess(self):
|
def startProcess(self):
|
||||||
try:
|
try:
|
||||||
cmd = mplayerCmd + ["-slave", "-idle"]
|
cmd = mplayerCmd + ["-slave", "-idle"]
|
||||||
|
devnull = file(os.devnull, "w")
|
||||||
self.mplayer = subprocess.Popen(
|
self.mplayer = subprocess.Popen(
|
||||||
cmd, startupinfo=si, stdin=subprocess.PIPE,
|
cmd, startupinfo=si, stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
stdout=devnull, stderr=devnull)
|
||||||
except OSError:
|
except OSError:
|
||||||
mplayerEvt.clear()
|
mplayerEvt.clear()
|
||||||
raise Exception("Audio player not found")
|
raise Exception("Audio player not found")
|
||||||
|
|
@ -178,21 +166,18 @@ def clearMplayerQueue():
|
||||||
mplayerEvt.set()
|
mplayerEvt.set()
|
||||||
|
|
||||||
def ensureMplayerThreads():
|
def ensureMplayerThreads():
|
||||||
global mplayerManager, mplayerReader
|
global mplayerManager
|
||||||
if not mplayerManager:
|
if not mplayerManager:
|
||||||
mplayerManager = MplayerMonitor()
|
mplayerManager = MplayerMonitor()
|
||||||
mplayerManager.daemon = True
|
mplayerManager.daemon = True
|
||||||
mplayerManager.start()
|
mplayerManager.start()
|
||||||
mplayerReader = MplayerReader()
|
|
||||||
mplayerReader.daemon = True
|
|
||||||
mplayerReader.start()
|
|
||||||
|
|
||||||
def stopMplayer(*args):
|
def stopMplayer(*args):
|
||||||
if not mplayerManager:
|
if not mplayerManager:
|
||||||
return
|
return
|
||||||
mplayerManager.kill()
|
mplayerManager.kill()
|
||||||
|
|
||||||
addHook("colClosed", stopMplayer)
|
addHook("unloadProfile", stopMplayer)
|
||||||
|
|
||||||
# PyAudio recording
|
# PyAudio recording
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue