diff options
| author | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-25 16:20:51 -0700 | 
|---|---|---|
| committer | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-25 16:20:51 -0700 | 
| commit | bd2fe67ac2e2f7c22bf279aeef5439820329e6dc (patch) | |
| tree | 5cbf8f8d45b84f383504941e02a844df46d19985 /realtime/rt/aligner.py | |
| parent | 17497f2e77e63e6aa549eedc279cac46cfd25e2b (diff) | |
Super multi-user thread safety update
Diffstat (limited to 'realtime/rt/aligner.py')
| -rw-r--r-- | realtime/rt/aligner.py | 11 | 
1 files changed, 10 insertions, 1 deletions
| diff --git a/realtime/rt/aligner.py b/realtime/rt/aligner.py index 80835412..a14121db 100644 --- a/realtime/rt/aligner.py +++ b/realtime/rt/aligner.py @@ -2,6 +2,7 @@ import logging  import os  import sys  import subprocess +import threading  import util @@ -29,10 +30,16 @@ class ForceAligner:          logging.info('Executing: {}'.format(' '.join(tools_cmd)))          self.tools = util.popen_io(tools_cmd) +        # Used to guarantee thread safety +        self.semaphore = threading.Semaphore() +      def align(self, source, target): +        '''Threadsafe'''          return self.align_formatted('{} ||| {}'.format(source, target))      def align_formatted(self, line): +        '''Threadsafe''' +        self.semaphore.acquire()          self.fwd_align.stdin.write('{}\n'.format(line))          self.rev_align.stdin.write('{}\n'.format(line))          # f words ||| e words ||| links ||| score @@ -40,7 +47,9 @@ class ForceAligner:          rev_line = self.rev_align.stdout.readline().split('|||')[2].strip()          self.tools.stdin.write('{}\n'.format(fwd_line))          self.tools.stdin.write('{}\n'.format(rev_line)) -        return self.tools.stdout.readline().strip() +        al_line = self.tools.stdout.readline().strip() +        self.semaphore.release() +        return al_line      def close(self):          self.fwd_align.stdin.close() | 
