Change over the price fetching code to a queue instead of a cv, fix some minor stuff

This commit is contained in:
cncfanatics
2010-09-21 20:54:30 +02:00
parent 2b4376614b
commit bdd959d75f
2 changed files with 8 additions and 29 deletions

View File

@@ -36,7 +36,7 @@ class PriceViewFull(StatsView):
self._timerRuns = 0 self._timerRuns = 0
self._timerIdUpdate = wx.NewId() self._timerIdUpdate = wx.NewId()
self._timerUpdate = None self._timerUpdate = None
def OnTimer( self, event): def OnTimer( self, event):
if self._timerId == event.GetId(): if self._timerId == event.GetId():
if self._timerRuns >= self._timerRunsBeforeUpdate: if self._timerRuns >= self._timerRunsBeforeUpdate:
@@ -81,7 +81,7 @@ class PriceViewFull(StatsView):
hbox.Add(lbl, 0, wx.ALIGN_LEFT) hbox.Add(lbl, 0, wx.ALIGN_LEFT)
hbox.Add(wx.StaticText(contentPanel, wx.ID_ANY, " ISK"), 0, wx.ALIGN_LEFT) hbox.Add(wx.StaticText(contentPanel, wx.ID_ANY, " ISK"), 0, wx.ALIGN_LEFT)
self.labelEMStatus = wx.StaticText(contentPanel, wx.ID_ANY, "") self.labelEMStatus = wx.StaticText(contentPanel, wx.ID_ANY, "")
contentSizer.Add(self.labelEMStatus,0) contentSizer.Add(self.labelEMStatus,0)
def refreshPanel(self, fit): def refreshPanel(self, fit):
if fit is not None: if fit is not None:

View File

@@ -23,48 +23,28 @@ import wx
import collections import collections
import threading import threading
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
import Queue
class PriceWorkerThread(threading.Thread): class PriceWorkerThread(threading.Thread):
def run(self): def run(self):
self.cv = threading.Condition() self.queue = Queue.Queue()
self.updateRequests = collections.deque()
self.scheduled = set()
self.processUpdates() self.processUpdates()
def processUpdates(self): def processUpdates(self):
updateRequests = self.updateRequests queue = self.queue
cv = self.cv
while True: while True:
cv.acquire()
while len(updateRequests) == 0:
cv.wait()
# Grab our data and rerelease the lock # Grab our data and rerelease the lock
callback, requests = self.updateRequests.popleft() callback, requests = queue.get()
self.scheduled.clear()
cv.release()
# Grab prices, this is the time-consuming part # Grab prices, this is the time-consuming part
if len(requests) > 0: if len(requests) > 0:
eos.types.Price.fetchPrices(*requests) eos.types.Price.fetchPrices(*requests)
wx.CallAfter(callback) wx.CallAfter(callback)
queue.task_done()
def trigger(self, prices, callbacks): def trigger(self, prices, callbacks):
self.cv.acquire() self.queue.put((callbacks, prices))
self.updateRequests.append((callbacks, prices))
self.scheduled.update(prices)
self.cv.notify()
self.cv.release()
def isScheduled(self, price):
self.cv.acquire()
scheduled = price in self.scheduled
self.cv.release()
return scheduled
class SearchWorkerThread(threading.Thread): class SearchWorkerThread(threading.Thread):
def run(self): def run(self):
@@ -258,7 +238,6 @@ class Market():
price = eos.types.Price(typeID) price = eos.types.Price(typeID)
eos.db.saveddata_session.add(price) eos.db.saveddata_session.add(price)
requests.append(price)
self.priceCache[typeID] = price self.priceCache[typeID] = price
requests.append(price) requests.append(price)