Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace PriorityQueue by Queue
Priority queue is not needed anymore; let's move to normal Queue to
store items to run in async worker.
  • Loading branch information
jasuarez committed May 6, 2012
1 parent 021903e commit d9704d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
28 changes: 3 additions & 25 deletions src/SeriesFinale/asyncworker.py
Expand Up @@ -19,6 +19,7 @@
###########################################################################

from threading import Thread
import Queue
import gobject
import logging
logging.basicConfig(level=logging.DEBUG)
Expand Down Expand Up @@ -54,7 +55,7 @@ class AsyncWorker(Thread):

def __init__(self):
Thread.__init__(self)
self.queue = PriorityQueue()
self.queue = Queue.Queue(0)
self.stopped = False
self.async_item = None
self.item_number = -1
Expand All @@ -68,6 +69,7 @@ def run(self):
self.async_item = self.queue.get()
self.item_number += 1
self.async_item.run()
self.queue.task_done()
self.async_item = None
except Exception, exception:
logging.debug(str(exception))
Expand All @@ -81,27 +83,3 @@ def stop(self):
def start(self):
self.stopped = False
Thread.start(self)

class PriorityQueue(list):

def __init__(self):
list.__init__(self)

def put(self, item):
(item_priority, item_element) = item
for i in range(0, len(self)):
(last_priority, last_element) = self[i]
if (last_priority > item_priority):
self.insert(i, item)
return
self.append(item)

def get(self):
if self:
value = self[0][1]
del self[0]
return value
return None

def empty(self):
return not bool(self)
12 changes: 6 additions & 6 deletions src/SeriesFinale/gui.py
Expand Up @@ -92,9 +92,9 @@ def __init__(self):
self._update_show_art)

self.request = AsyncWorker()
self.request.queue.put((0, save_pid))
self.request.queue.put((0, load_conf_item))
self.request.queue.put((0, load_shows_item))
self.request.queue.put(save_pid)
self.request.queue.put(load_conf_item)
self.request.queue.put(load_shows_item)

old_pid = self.get_previous_pid()

Expand Down Expand Up @@ -339,8 +339,8 @@ def _exit_cb(self, window, event):
(constants.SF_CONF_FILE,),
self._save_finished_cb)
async_worker = AsyncWorker()
async_worker.queue.put((0, save_shows_item))
async_worker.queue.put((0, save_conf_item))
async_worker.queue.put(save_shows_item)
async_worker.queue.put(save_conf_item)
async_worker.start()

def _save_finished_cb(self, dummy_arg, error):
Expand Down Expand Up @@ -599,7 +599,7 @@ def update_pixmaps(self, show = None):
(current_show, pixbuf),
self._load_pixmap_async_finished,
(current_show,))
async_worker.queue.put((0, async_item))
async_worker.queue.put(async_item)
if same_show:
break
iter = self.iter_next(iter)
Expand Down
10 changes: 5 additions & 5 deletions src/SeriesFinale/series.py
Expand Up @@ -512,7 +512,7 @@ def search_shows(self, terms, language = "en"):
async_item = AsyncItem(self.thetvdb.get_matching_shows,
(terms, language,),
self._search_finished_callback)
self.async_worker.queue.put((0, async_item))
self.async_worker.queue.put(async_item)
self.async_worker.start()

def _search_finished_callback(self, tvdbshows, error):
Expand All @@ -537,11 +537,11 @@ def update_all_shows_episodes(self, show_list = []):
(show.thetvdb_id, show.language,),
self._set_show_episodes_complete_cb,
(show, i == n_shows - 1))
async_worker.queue.put((0, async_item))
async_worker.queue.put(async_item)
async_item = AsyncItem(self._set_show_images,
(show,),
None,)
async_worker.queue.put((1, async_item))
async_worker.queue.put(async_item)
async_worker.start()
return async_worker

Expand Down Expand Up @@ -572,7 +572,7 @@ def get_complete_show(self, show_name, language = "en"):
async_item = AsyncItem(self._get_complete_show_from_id,
(show_id, language,),
self._get_complete_show_finished_cb)
self.async_worker.queue.put((0, async_item))
self.async_worker.queue.put(async_item)
self.async_worker.start()

def _get_complete_show_from_id(self, show_id, language):
Expand Down Expand Up @@ -600,7 +600,7 @@ def _get_complete_show_finished_cb(self, show, error):
async_item = AsyncItem(self._set_show_images,
(show,),
None,)
self.async_worker.queue.put((1, async_item))
self.async_worker.queue.put(async_item)
if not self.async_worker.isAlive():
self.async_worker.start()

Expand Down

0 comments on commit d9704d7

Please sign in to comment.