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

Skip to content

Commit f3b15dc

Browse files
committed
dynamic timeout
1 parent 72b0db1 commit f3b15dc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

server.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def parse_parser_results(text):
3838
elif state == 2:
3939
if not line.startswith("[Text="):
4040
print line
41-
raise Exception("Parse error")
41+
raise Exception("Parse error. Could not find [Text=")
4242
tmp['words'] = {}
4343
exp = re.compile('\[([a-zA-Z0-9=. ]+)\]')
4444
m = exp.findall(line)
@@ -54,8 +54,9 @@ def parse_parser_results(text):
5454
tmp['tuples'] = []
5555
if state == 4:
5656
# dependency parse
57-
if not line.startswith(" ") and line.rstrip().endswith(")"):
58-
split_entry = re.split("\(|, ", line[:-2])
57+
line = line.rstrip()
58+
if not line.startswith(" ") and line.endswith(")"):
59+
split_entry = re.split("\(|, ", line[:-1])
5960
if len(split_entry) == 3:
6061
rel, left, right = map(lambda x: remove_id(x), split_entry)
6162
tmp['tuples'].append((rel,left,right))
@@ -119,11 +120,13 @@ def parse(self, text):
119120
"""
120121
print "Request", text
121122
print self._server.sendline(text)
122-
end_time = time.time() + 2
123+
max_expected_time = 2 + len(text) / 200.0
124+
print "Timeout", max_expected_time
125+
end_time = time.time() + max_expected_time
123126
incoming = ""
124127
while True:
125-
# Still have time left, so read more data
126-
ch = self._server.read_nonblocking (2000, 3)
128+
# Time left, read more data
129+
ch = self._server.read_nonblocking (2000, max_expected_time)
127130
freshlen = len(ch)
128131
time.sleep (0.0001)
129132
incoming = incoming + ch

0 commit comments

Comments
 (0)
0