| 49 | |
| 50 | |
| 51 | class ShipBrowserWorkerThread(threading.Thread): |
| 52 | def __init__(self): |
| 53 | threading.Thread.__init__(self) |
| 54 | pyfalog.debug("Initialize ShipBrowserWorkerThread.") |
| 55 | self.name = "ShipBrowser" |
| 56 | self.running = True |
| 57 | |
| 58 | def run(self): |
| 59 | self.queue = queue.Queue() |
| 60 | self.cache = {} |
| 61 | # Wait for full market initialization (otherwise there's high risky |
| 62 | # this thread will attempt to init Market which is already being inited) |
| 63 | mktRdy.wait(5) |
| 64 | self.processRequests() |
| 65 | |
| 66 | def processRequests(self): |
| 67 | queue = self.queue |
| 68 | cache = self.cache |
| 69 | sMkt = Market.getInstance() |
| 70 | while True: |
| 71 | if not self.running: |
| 72 | break |
| 73 | try: |
| 74 | id_, callback = queue.get() |
| 75 | set_ = cache.get(id_) |
| 76 | if set_ is None: |
| 77 | set_ = sMkt.getShipList(id_) |
| 78 | cache[id_] = set_ |
| 79 | |
| 80 | wx.CallAfter(callback, (id_, set_)) |
| 81 | except (KeyboardInterrupt, SystemExit): |
| 82 | raise |
| 83 | except Exception as e: |
| 84 | pyfalog.critical("Callback failed.") |
| 85 | pyfalog.critical(e) |
| 86 | finally: |
| 87 | try: |
| 88 | queue.task_done() |
| 89 | except (KeyboardInterrupt, SystemExit): |
| 90 | raise |
| 91 | except Exception as e: |
| 92 | pyfalog.critical("Queue task done failed.") |
| 93 | pyfalog.critical(e) |
| 94 | |
| 95 | def stop(self): |
| 96 | self.running = False |
| 97 | |
| 98 | |
| 99 | class SearchWorkerThread(threading.Thread): |