@@ -143,6 +143,14 @@ def _parse(self, text, verbose=True):
143
143
It returns a Python data-structure, while the parse()
144
144
function returns a JSON object
145
145
"""
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
+
146
154
self ._server .sendline (text )
147
155
# How much time should we give the parser to parse it?
148
156
# the idea here is that you increase the timeout as a
@@ -156,16 +164,23 @@ def _parse(self, text, verbose=True):
156
164
incoming = ""
157
165
while True :
158
166
# 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 "\n NLP>" 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 "\n NLP>" 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 :
164
183
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 }
169
184
results = parse_parser_results (incoming )
170
185
return results
171
186
0 commit comments