Changeset 793:fea44dadc477
- Timestamp:
- 07/24/16 08:46:13 (8 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/fsuipc.py
r790 r793 118 118 119 119 @staticmethod 120 def _performRead(data, callback, extra, validator ):120 def _performRead(data, callback, extra, validator, unimportant = False): 121 121 """Perform a read request. 122 122 … … 130 130 attemptsLeft = Handler.NUM_READATTEMPTS 131 131 while attemptsLeft>0: 132 values = pyuipc.read(data) 133 if validator is None or \ 134 Handler._callSafe(lambda: validator(values, extra)): 132 exception = None 133 try: 134 values = pyuipc.read(data) 135 except TypeError, e: 136 exception = e 137 138 failed = True 139 if (exception is None or unimportant) and \ 140 (validator is None or \ 141 Handler._callSafe(lambda: validator(values, extra))): 135 142 Handler._callSafe(lambda: callback(values, extra)) 143 failed = False 144 145 if exception is not None: 146 raise exception 147 148 if failed: 149 attemptsLeft -= 1 150 else: 136 151 return True 137 else:138 attemptsLeft -= 1139 152 return False 140 153 141 154 class Request(object): 142 155 """A simple, one-shot request.""" 143 def __init__(self, forWrite, data, callback, extra, validator = None): 156 def __init__(self, forWrite, data, callback, extra, 157 validator = None, unimportant = False): 144 158 """Construct the request.""" 145 159 self._forWrite = forWrite … … 148 162 self._extra = extra 149 163 self._validator = validator 164 self.unimportant = unimportant 150 165 151 166 def process(self, time): … … 156 171 if there is some lower-level communication problem.""" 157 172 if self._forWrite: 158 pyuipc.write(self._data) 159 Handler._callSafe(lambda: self._callback(True, self._extra)) 173 exception = None 174 try: 175 pyuipc.write(self._data) 176 except TypeError, e: 177 exception = e 178 179 if exception is None or self.unimportant: 180 Handler._callSafe(lambda: self._callback(True, 181 self._extra)) 182 183 if exception is not None: 184 raise exception 185 160 186 return True 161 187 else: 162 188 return Handler._performRead(self._data, self._callback, 163 self._extra, self._validator) 189 self._extra, self._validator, 190 self.unimportant) 164 191 165 192 def fail(self): … … 267 294 self._requestCondition.notify() 268 295 269 def requestWrite(self, data, callback, extra = None ):296 def requestWrite(self, data, callback, extra = None, unimportant = False): 270 297 """Request the writing of some data. 271 298 … … 281 308 """ 282 309 with self._requestCondition: 283 request = Handler.Request(True, data, callback, extra) 310 request = Handler.Request(True, data, callback, extra, 311 unimportant = unimportant) 284 312 #print "fsuipc.Handler.requestWrite", request 285 313 self._requests.append(request) … … 451 479 print "fsuipc.Handler._processRequest: FSUIPC returned invalid data too many times, reconnecting" 452 480 needReconnect = True 481 except TypeError as e: 482 print "fsuipc.Handler._processRequest: type error: " + \ 483 util.utf2unicode(str(e)) + \ 484 ("." if request.unimportant else 485 (", reconnecting (attempts=%d)." % (attempts,))) 486 needReconnect = not request.unimportant 453 487 except Exception as e: 454 488 print "fsuipc.Handler._processRequest: FSUIPC connection failed (" + \
Note:
See TracChangeset
for help on using the changeset viewer.