python - Broken pipe during a subprocess stdin.write -
i interact server use tag sentences. server launched locally on port 2020
.
for example, if send je mange des pâtes .
on port 2020
through client used below, server answers je_cl mange_v des_p pâtes_n ._.
, result 1 line only, , 1 line if input not empty.
i have tag 9 568 files through server. first 9 483 files tagged expected. after that, input stream seems closed / full / else because ioerror
, broken pipe
error when try write on stdin
.
when skip first 9 483 first files, last ones tagged without issue, including 1 causing first error.
my server doesn't produce error log indicating fishy happened... handle incorrectly? normal pipe fails after time?
log = codecs.open('stanford-tagger.log', 'w', 'utf-8') p1 = popen(["java", "-cp", jar, "edu.stanford.nlp.tagger.maxent.maxenttaggerserver", "-client", "-port", "2020"], stdin=pipe, stdout=pipe, stderr=log) fhi = codecs.open(summary, 'r', 'utf-8') # descriptor of files tag i, line in enumerate(fhi, 1): if % 500: print "tagged " + str(i) + " documents..." tokens = ... # list of words, can quite long try: p1.stdin.write(' '.join(tokens).encode('utf-8') + '\n') except ioerror: print 'bouh, failed ;((' result = p1.stdout.readline() # here result... fhi.close()
in addition comments, might suggest few other changes...
for i, line in enumerate(fhi, 1): if % 500: print "tagged " + str(i) + " documents..." tokens = ... # list of words, can quite long try: s = ' '.join(tokens).encode('utf-8') + '\n' assert s.find('\n') == len(s) - 1 # make sure there's 1 cr in s p1.stdin.write(s) p1.stdin.flush() # block until we're sure it's been sent except ioerror: print 'bouh, failed ;((' result = p1.stdout.readline() assert result # make sure got assert result.find('\n') == len(result) - 1 # make sure there's 1 cr in result # here result... fhi.close()
...but given there's client/server of know nothing about, there's lot of places going wrong.
does work if dump queries single file, , run commandline like...
java .... < input > output
Comments
Post a Comment