diff options
| author | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-27 13:39:24 -0700 | 
|---|---|---|
| committer | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-27 13:39:24 -0700 | 
| commit | 6fd8326590fbe02d97ca2e897a95131b47413b09 (patch) | |
| tree | bf1678cf4596a02f3b406ead14e968fca492aaad /realtime/realtime.py | |
| parent | ce358ecd6f5132f8bdbbda2272ff4f04ff883e30 (diff) | |
Decoding and learning with multiple contexts is threadsafe and FIFO.
Diffstat (limited to 'realtime/realtime.py')
| -rwxr-xr-x | realtime/realtime.py | 17 | 
1 files changed, 11 insertions, 6 deletions
diff --git a/realtime/realtime.py b/realtime/realtime.py index bbec288b..38da4413 100755 --- a/realtime/realtime.py +++ b/realtime/realtime.py @@ -31,22 +31,27 @@ def test1(translator, input, output, ctx_name):      out.close()  def debug(translator, input): -    # Test 1: identical output +    # Test 1: multiple contexts      threads = []      for i in range(4):          t = threading.Thread(target=test1, args=(translator, input, '{}.out.{}'.format(input, i), str(i)))          threads.append(t)          t.start()          time.sleep(30) -    for t in threads: -        t.join() -    # Test 2: flood (same number of lines) -    threads = [] +    # Test 2: flood      out = open('{}.out.flood'.format(input), 'w') -    for line in open(input): +    inp = open(input) +    while True: +        line = inp.readline() +        if not line: +            break +        line = line.strip()          t = threading.Thread(target=handle_line, args=(translator, line.strip(), out, None))          threads.append(t)          t.start() +        time.sleep(1)  +    translator.drop_ctx(None) +    # Join test threads      for t in threads:          t.join()  | 
