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
commitce358ecd6f5132f8bdbbda2272ff4f04ff883e30 (patch)
treeb5f2e114df1c8f23e9727c113e3ccf6d2964da29 /realtime/rt/decoder.py
parent0d0db26fff5cec36397d81a4f1d15e4efea29f73 (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