summaryrefslogtreecommitdiff
path: root/realtime/rt/decoder.py
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-26 14:28:42 -0700
committerMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-26 14:28:42 -0700
commitcb718c763e07b8e1417383ef7ae5c1aca36d2a0a (patch)
tree2c4495650f59ab6b085ff95cef25bb05776232a8 /realtime/rt/decoder.py
parent49ddc45e717ac495c6adf80a20d02a1672a069df (diff)
FIFO Locks
Diffstat (limited to 'realtime/rt/decoder.py')
-rw-r--r--realtime/rt/decoder.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/realtime/rt/decoder.py b/realtime/rt/decoder.py
index 72b5b959..7c36b441 100644
--- a/realtime/rt/decoder.py
+++ b/realtime/rt/decoder.py
@@ -9,18 +9,18 @@ class Decoder:
def close(self, force=False):
if not force:
- self.semaphore.acquire()
+ self.lock.acquire()
self.decoder.stdin.close()
if not force:
- self.semaphore.release()
+ self.lock.release()
def decode(self, sentence, grammar=None):
'''Threadsafe'''
input = '<seg grammar="{g}">{s}</seg>\n'.format(s=sentence, g=grammar) if grammar else '{}\n'.format(sentence)
- self.semaphore.acquire()
+ self.lock.acquire()
self.decoder.stdin.write(input)
hyp = self.decoder.stdout.readline().strip()
- self.semaphore.release()
+ self.lock.release()
return hyp
class CdecDecoder(Decoder):
@@ -31,7 +31,7 @@ class CdecDecoder(Decoder):
decoder_cmd = [decoder, '-c', config, '-w', weights]
logging.info('Executing: {}'.format(' '.join(decoder_cmd)))
self.decoder = util.popen_io(decoder_cmd)
- self.semaphore = threading.Semaphore()
+ self.lock = util.FIFOLock()
class MIRADecoder(Decoder):
@@ -42,27 +42,27 @@ class MIRADecoder(Decoder):
mira_cmd = [mira, '-c', config, '-w', weights, '-o', '2', '-C', '0.001', '-b', '500', '-k', '500', '-u', '-t']
logging.info('Executing: {}'.format(' '.join(mira_cmd)))
self.decoder = util.popen_io(mira_cmd)
- self.semaphore = threading.Semaphore()
+ self.lock = util.FIFOLock()
def get_weights(self):
'''Threadsafe'''
- self.semaphore.acquire()
+ self.lock.acquire()
self.decoder.stdin.write('WEIGHTS ||| WRITE\n')
weights = self.decoder.stdout.readline().strip()
- self.semaphore.release()
+ self.lock.release()
return weights
def set_weights(self, w_line):
'''Threadsafe'''
- self.semaphore.acquire()
+ self.lock.acquire()
self.decoder.stdin.write('WEIGHTS ||| {}\n'.format(w_line))
- self.semaphore.release()
+ self.lock.release()
def update(self, sentence, grammar, reference):
'''Threadsafe'''
input = 'LEARN ||| <seg grammar="{g}">{s}</seg> ||| {r}\n'.format(s=sentence, g=grammar, r=reference)
- self.semaphore.acquire()
+ self.lock.acquire()
self.decoder.stdin.write(input)
log = self.decoder.stdout.readline().strip()
- self.semaphore.release()
+ self.lock.release()
return log