exchange rate plugin: keep thread running (fixes #494)
This commit is contained in:
parent
2a9c62c9b8
commit
4f78b5365b
|
@ -20,6 +20,7 @@ class Exchanger(threading.Thread):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.quote_currencies = None
|
self.quote_currencies = None
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
self.is_running = False
|
||||||
|
|
||||||
def exchange(self, btc_amount, quote_currency):
|
def exchange(self, btc_amount, quote_currency):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
@ -30,7 +31,16 @@ class Exchanger(threading.Thread):
|
||||||
return None
|
return None
|
||||||
return btc_amount * quote_currencies[quote_currency]
|
return btc_amount * quote_currencies[quote_currency]
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.is_running = False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.is_running = True
|
||||||
|
while self.is_running:
|
||||||
|
self.update()
|
||||||
|
time.sleep(120)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
try:
|
try:
|
||||||
connection = httplib.HTTPConnection('blockchain.info')
|
connection = httplib.HTTPConnection('blockchain.info')
|
||||||
connection.request("GET", "/ticker")
|
connection.request("GET", "/ticker")
|
||||||
|
@ -49,9 +59,10 @@ class Exchanger(threading.Thread):
|
||||||
quote_currencies[r] = self._lookup_rate(response, r)
|
quote_currencies[r] = self._lookup_rate(response, r)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.quote_currencies = quote_currencies
|
self.quote_currencies = quote_currencies
|
||||||
self.parent.set_currencies(quote_currencies)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
self.parent.set_currencies(quote_currencies)
|
||||||
|
# print "updating exchange rate", self.quote_currencies["USD"]
|
||||||
|
|
||||||
|
|
||||||
def get_currencies(self):
|
def get_currencies(self):
|
||||||
|
@ -110,6 +121,10 @@ class Plugin(BasePlugin):
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.exchanger.stop()
|
||||||
|
|
||||||
|
|
||||||
def settings_widget(self, window):
|
def settings_widget(self, window):
|
||||||
combo = QComboBox()
|
combo = QComboBox()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue