diff options
author | Philip Withnall <pwithnall@svn.gnome.org> | 2008-02-15 11:50:29 +0000 |
---|---|---|
committer | Philip Withnall <pwithnall@src.gnome.org> | 2008-02-15 11:50:29 +0000 |
commit | 4030c682937d154c4afc2fa2c009ab9f4a3fda59 (patch) | |
tree | 2be844e36e683344df2ee23d41aa345684648a9a /src/plugins | |
parent | bbad9a9491b57d29fad17bd61c7f59a7168c92db (diff) |
Add proper locking to the entry list, hopefully stopping any potential
2008-02-15 Philip Withnall <pwithnall@svn.gnome.org>
* src/plugins/youtube/youtube.py: Add proper locking to the
entry list, hopefully stopping any potential races.
svn path=/trunk/; revision=5127
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/youtube/youtube.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/plugins/youtube/youtube.py b/src/plugins/youtube/youtube.py index dd2af6e5..dd3c59b9 100644 --- a/src/plugins/youtube/youtube.py +++ b/src/plugins/youtube/youtube.py @@ -15,8 +15,9 @@ class DownloadThread (threading.Thread): self.treeview_name = treeview_name threading.Thread.__init__ (self) def run (self): + self.youtube.entry_lock.acquire (True) self.youtube.entry[self.treeview_name] = self.youtube.service.Get (self.url).entry - self.youtube.results_downloaded = True + self.youtube.entry_lock.release () class YouTube (totem.Plugin): def __init__ (self): @@ -25,7 +26,6 @@ class YouTube (totem.Plugin): self.max_results = 20 self.button_down = False - self.results_downloaded = True self.search_terms = "" self.youtube_id = "" @@ -33,6 +33,7 @@ class YouTube (totem.Plugin): self.start_index = {} self.results = {} # This is just the number of results from the last pagination query self.entry = {} + self.entry_lock = threading.Lock () self.current_treeview_name = "" self.notebook_pages = [] @@ -142,17 +143,20 @@ class YouTube (totem.Plugin): """Find the last clause in the URL; after the last /""" return url.split ("/").pop () def populate_list_from_results (self, treeview_name): - """Wait until we have some results to display, or return if there are none (or we've finished)""" + """Check and acquire the lock""" + if self.entry_lock.acquire (False) == False: + return True + + """Return if there are no results (or we've finished)""" if self.entry[treeview_name] == None or len (self.entry[treeview_name]) == 0: - if self.results_downloaded: - """Revert the cursor""" - window = self.vbox.window - window.set_cursor (None) + """Revert the cursor""" + window = self.vbox.window + window.set_cursor (None) - self.entry[treeview_name] = None - return False - else: - return True + self.entry[treeview_name] = None + self.entry_lock.release () + + return False """Only do one result at a time, as the thumbnail has to be downloaded; give them a temporary MRL until the real one is resolved before playing""" entry = self.entry[treeview_name].pop (0) @@ -161,6 +165,8 @@ class YouTube (totem.Plugin): youtube_id = self.convert_url_to_id (entry.id.text) mrl = "http://www.youtube.com/v/" + urllib.quote (youtube_id) + self.entry_lock.release () + """Find the thumbnail tag""" for _element in entry.extension_elements: if _element.tag == "group": |