eric7/E5Network/E5JsonClient.py

branch
eric7
changeset 8327
666c2b81cbb7
parent 8312
800c432b34c8
equal deleted inserted replaced
8325:547319e56c60 8327:666c2b81cbb7
153 153
154 # Give time to process latest response on server side 154 # Give time to process latest response on server side
155 with contextlib.suppress(socket.error, OSError): 155 with contextlib.suppress(socket.error, OSError):
156 self.__connection.shutdown(socket.SHUT_RDWR) 156 self.__connection.shutdown(socket.SHUT_RDWR)
157 self.__connection.close() 157 self.__connection.close()
158
159 def poll(self, waitMethod=""):
160 """
161 Public method to check and receive one message (if available).
162
163 @param waitMethod name of a method to wait for
164 @type str
165 @return dictionary containing the data of the waited for method
166 @rtype dict
167 """
168 try:
169 if waitMethod:
170 rrdy, wrdy, xrdy = select.select(
171 [self.__connection], [], [])
172 else:
173 rrdy, wrdy, xrdy = select.select(
174 [self.__connection], [], [], 0)
175
176 if self.__connection in rrdy:
177 method, params = self.__receiveJson()
178 if method is not None:
179 if method == "Exit":
180 self.__exitClient = True
181 elif method == waitMethod:
182 return params
183 else:
184 self.handleCall(method, params)
185
186 except (select.error, KeyboardInterrupt, socket.error):
187 # just ignore these
188 pass
189
190 except Exception:
191 exctype, excval, exctb = sys.exc_info()
192 tbinfofile = io.StringIO()
193 traceback.print_tb(exctb, None, tbinfofile)
194 tbinfofile.seek(0)
195 tbinfo = tbinfofile.read()
196 del exctb
197 self.sendJson("ClientException", {
198 "ExceptionType": str(exctype),
199 "ExceptionValue": str(excval),
200 "Traceback": tbinfo,
201 })
202
203 return None

eric ide

mercurial