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._timerIdUpdate = wx.NewId()
self._timerUpdate = None
def OnTimer( self, event):
if self._timerId == event.GetId():
if self._timerRuns >= self._timerRunsBeforeUpdate:
@@ -81,7 +81,7 @@ class PriceViewFull(StatsView):
hbox.Add(lbl, 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)
def refreshPanel(self, fit):
if fit is not None:

View File

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