From: Akira ODA Date: 2007-03-04T16:21:48+09:00 Subject: [ruby-dev:30479] Re: ThreadError on shell.rb 尾田です。 > ちょっと試しましたが, 再現するのはなかなか難しそうです... > 実行すると必ず再現します? いえ、少ないファイル数ならエラーが起きないこともあります。 2,000ファイル以上処理したところでとまったと思ったら、150ファイルほど でとまる場合もあるようです。 > commands(ARGV)に渡すコマンドは何でしょうか? 自作のPython スクリプトです。で、 % ./bin/dir_filter.rb -f from -t to -- python ./bin/clean_sentence.py -l list.txt みたいな感じで走らせてます。一応のせておきます。 # 念のため、今、代わりにgrep を使って実行してみています。 そういえば、前のメールに書くのを忘れてましたが、top で眺めていると実行した 子プロセス(Python)がたまに defunct になってました。あと、関係あるかどうか 分かりませんが、入力、出力のファイルとも NFS でマウントされたファイルです。 import sys import fileinput def sentences(fp): sentence_id = None source = None for line in fp: if line.startswith('# FILE'): continue if line.startswith('# '): sentence_id = line[2:].rstrip() elif line.startswith('#SRC: '): source = line[5:].rstrip() elif len(line.strip()) > 0: yield sentence_id, source, line.rstrip() def main(args, list_file): duplicate_ids = read_id(list_file) for sentence_id, source, tree in sentences(fileinput.input(args)): if sentence_id not in duplicate_ids: docid, para, sent = sentence_id.split('-') print '# %s-%03d-%03d' % (docid, int(para), int(sent)) print '#SRC: %s' % source print tree print def read_id(list_file): fp = file(list_file) ids = set() for line in fp: for id in line.rstrip().split('\t')[1:]: ids.add(id) fp.close() return ids if __name__ == '__main__': import optparse parser = optparse.OptionParser() parser.add_option('--list', '-l', dest='list_file') (options, args) = parser.parse_args() if not options.list_file: parser.print_help() sys.exit(1) main(args, options.list_file) -- Akira ODA Junior Research Scientist Department of Computer Science, New York University.