thread for hooks
| 421 | |
| 422 | |
| 423 | class HookThread(PluginThread): |
| 424 | """thread for hooks""" |
| 425 | |
| 426 | #---------------------------------------------------------------------- |
| 427 | def __init__(self, m, function, args, kwargs): |
| 428 | """Constructor""" |
| 429 | PluginThread.__init__(self, m) |
| 430 | |
| 431 | self.f = function |
| 432 | self.args = args |
| 433 | self.kwargs = kwargs |
| 434 | |
| 435 | self.active = [] |
| 436 | |
| 437 | m.localThreads.append(self) |
| 438 | |
| 439 | self.start() |
| 440 | |
| 441 | def getActiveFiles(self): |
| 442 | return self.active |
| 443 | |
| 444 | def addActive(self, pyfile): |
| 445 | """ Adds a pyfile to active list and thus will be displayed on overview""" |
| 446 | if pyfile not in self.active: |
| 447 | self.active.append(pyfile) |
| 448 | |
| 449 | def finishFile(self, pyfile): |
| 450 | if pyfile in self.active: |
| 451 | self.active.remove(pyfile) |
| 452 | |
| 453 | pyfile.finishIfDone() |
| 454 | |
| 455 | def run(self): |
| 456 | try: |
| 457 | try: |
| 458 | self.kwargs["thread"] = self |
| 459 | self.f(*self.args, **self.kwargs) |
| 460 | except TypeError, e: |
| 461 | #dirty method to filter out exceptions |
| 462 | if "unexpected keyword argument 'thread'" not in e.args[0]: |
| 463 | raise |
| 464 | |
| 465 | del self.kwargs["thread"] |
| 466 | self.f(*self.args, **self.kwargs) |
| 467 | finally: |
| 468 | local = copy(self.active) |
| 469 | for x in local: |
| 470 | self.finishFile(x) |
| 471 | |
| 472 | self.m.localThreads.remove(self) |
| 473 | |
| 474 | |
| 475 | class InfoThread(PluginThread): |