src/eric7/Utilities/BackgroundService.py

branch
eric7
changeset 10072
891e71c29be0
parent 9656
578236b57ed5
child 10080
f834e57a5b13
equal deleted inserted replaced
10071:a74e32fa4d23 10072:891e71c29be0
187 187
188 @param lang language of the incoming connection 188 @param lang language of the incoming connection
189 @type str 189 @type str
190 @exception RuntimeError raised if hashes don't match 190 @exception RuntimeError raised if hashes don't match
191 """ 191 """
192 data = ""
193 fx = ""
194
192 connection = self.connections[lang] 195 connection = self.connections[lang]
193 while connection.bytesAvailable(): 196 while connection.bytesAvailable():
194 if self.__cancelled:
195 connection.readAll()
196 continue
197
198 header = connection.read(struct.calcsize(b"!II")) 197 header = connection.read(struct.calcsize(b"!II"))
199 length, datahash = struct.unpack(b"!II", header) 198 length, datahash = struct.unpack(b"!II", header)
200 199
201 packedData = b"" 200 packedData = b""
202 while len(packedData) < length: 201 while len(packedData) < length:
264 " service." 263 " service."
265 ), 264 ),
266 ) 265 )
267 if res != EricMessageBox.No: 266 if res != EricMessageBox.No:
268 self.isWorking = None 267 self.isWorking = None
269 self.restartService(lang, True) 268 self.restartService(lang, forceKill=True)
270 return 269 return
271 elif data == "Unknown service.": 270 elif data == "Unknown service.":
272 callback = self.services.get((fx, lang)) 271 callback = self.services.get((fx, lang))
273 if callback: 272 if callback:
274 callback[3](fx, lang, fn, data) 273 callback[3](fx, lang, fn, data)
275 elif fx.startswith("batch_"): 274 elif fx.startswith("batch_"):
276 fx = fx.replace("batch_", "") 275 mfx = fx.replace("batch_", "")
277 if data != "__DONE__": 276 if data != "__DONE__":
278 callback = self.services.get((fx, lang)) 277 callback = self.services.get((mfx, lang))
279 if callback: 278 if callback:
280 if isinstance(data, (list, tuple)): 279 if isinstance(data, (list, tuple)):
281 callback[2](fn, *data) 280 callback[2](fn, *data)
282 elif isinstance(data, str): 281 elif isinstance(data, str):
283 callback[3](fx, lang, fn, data) 282 callback[3](mfx, lang, fn, data)
284 if data == "Unknown batch service.": 283 if data == "Unknown batch service.":
285 self.batchJobDone.emit(fx, lang) 284 self.batchJobDone.emit(mfx, lang)
286 self.__cancelled = True 285 self.__cancelled = True
287 else: 286 else:
288 self.batchJobDone.emit(fx, lang) 287 self.batchJobDone.emit(mfx, lang)
289 self.restartService(lang, forceKill=True) 288 self.restartService(lang, forceKill=True)
290 else: 289 else:
291 callback = self.services.get((fx, lang)) 290 callback = self.services.get((fx, lang))
292 if callback: 291 if callback:
293 callback[2](fn, *data) 292 callback[2](fn, *data)
293
294 if self.__cancelled and data != "__DONE__" and fx.startswith("batch_"):
295 # If it is a canceled batch job perform the batch done logic.
296 fx = fx.replace("batch_", "")
297 self.batchJobDone.emit(fx, lang)
298 self.restartService(lang, forceKill=True)
294 299
295 self.isWorking = None 300 self.isWorking = None
296 self.__processQueue() 301 self.__processQueue()
297 302
298 def preferencesOrProjectChanged(self): 303 def preferencesOrProjectChanged(self):
378 @param fx function name of the service 383 @param fx function name of the service
379 @type str 384 @type str
380 @param lang language to connect to 385 @param lang language to connect to
381 @type str 386 @type str
382 """ 387 """
383 self.__cancelled = True
384
385 entriesToRemove = [] 388 entriesToRemove = []
386 for pendingArg in self.__queue: 389 for pendingArg in self.__queue:
387 if pendingArg[:2] == [fx, lang]: 390 if pendingArg[:2] == [fx, lang]:
388 entriesToRemove.append(pendingArg) 391 entriesToRemove.append(pendingArg)
389 for entryToRemove in entriesToRemove: 392 for entryToRemove in entriesToRemove:
394 return 397 return
395 else: 398 else:
396 header = struct.pack(b"!II", 0, 0) 399 header = struct.pack(b"!II", 0, 0)
397 connection.write(header) 400 connection.write(header)
398 connection.write(b"CANCEL") # 6 character message type 401 connection.write(b"CANCEL") # 6 character message type
402
403 self.__cancelled = True
399 404
400 def serviceConnect( 405 def serviceConnect(
401 self, 406 self,
402 fx, 407 fx,
403 lang, 408 lang,

eric ide

mercurial