summaryrefslogtreecommitdiff
path: root/realtime/rt
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-25 18:45:28 -0700
committerMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-25 18:45:28 -0700
commit0d0db26fff5cec36397d81a4f1d15e4efea29f73 (patch)
treec780891a7f9e74857e0ed79cc4cc22d7bd800118 /realtime/rt
parentbd2fe67ac2e2f7c22bf279aeef5439820329e6dc (diff)
Threading tests
Diffstat (limited to 'realtime/rt')
-rw-r--r--realtime/rt/rt.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/realtime/rt/rt.py b/realtime/rt/rt.py
index 6f1fb70f..f8126283 100644
--- a/realtime/rt/rt.py
+++ b/realtime/rt/rt.py
@@ -101,6 +101,8 @@ class RealtimeTranslator:
# ctx -> list of (source, target, alignment)
self.ctx_data = {}
+ # Grammar extractor is not threadsafe
+ self.extractor_sem = threading.Semaphore()
# ctx -> deque of file
self.grammar_files = {}
# ctx -> dict of {sentence: file}
@@ -181,8 +183,10 @@ class RealtimeTranslator:
(fid, grammar_file) = tempfile.mkstemp(dir=self.decoders[ctx_name].tmp, prefix='grammar.')
os.close(fid)
with open(grammar_file, 'w') as output:
+ self.extractor_sem.acquire()
for rule in self.extractor.grammar(sentence, ctx_name):
output.write('{}\n'.format(str(rule)))
+ self.extractor_sem.release()
grammar_files = self.grammar_files[ctx_name]
if len(grammar_files) == self.cache_size:
rm_sent = grammar_files.popleft()