8000 timeout · rocipher/stanford-corenlp-python@3207767 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3207767

Browse files
committed
timeout
1 parent 6bc663d commit 3207767

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

corenlp.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ def _parse(self, text, verbose=True):
143143
It returns a Python data-structure, while the parse()
144144
function returns a JSON object
145145
"""
146+
while True:
147+
try:
148+
ch = self._server.read_nonblocking (2000, 1)
149+
except pexpect.TIMEOUT:
150+
break
151+
152+
# clean up anything leftover
153+
146154
self._server.sendline(text)
147155
# How much time should we give the parser to parse it?
148156
# the idea here is that you increase the timeout as a
@@ -156,16 +164,23 @@ def _parse(self, text, verbose=True):
156164
incoming = ""
157165
while True:
158166
# Time left, read more data
159-
ch = self._server.read_nonblocking (2000, max_expected_time)
160-
freshlen = len(ch)
161-
time.sleep (0.0001)
162-
incoming = incoming + ch
163-
if "\nNLP>" in incoming:
167+
try:
168+
ch = self._server.read_nonblocking (2000, 1)
169+
freshlen = len(ch)
170+
time.sleep (0.0001)
171+
incoming = incoming + ch
172+
if "\nNLP>" in incoming:
173+
break
174+
except pexpect.TIMEOUT:
175+
print "Timeout"
176+
if end_time - time.time() < 0:
177+
return {'error': "timed out after %f seconds" % max_expected_time,
178+
'input': text,
179+
'output': incoming}
180+
else:
181+
continue
182+
except pexpect.EOF:
164183
break
165-
if end_time - time.time() < 0:
166-
return {'error': "timed out after %f seconds" % max_expected_time,
167-
'input': text,
168-
'output': incoming}
169184
results = parse_parser_results(incoming)
170185
return results
171186

0 commit comments

Comments
 (0)
0