totem r5127 - in trunk: . src/plugins/youtube



Author: pwithnall
Date: Fri Feb 15 11:50:29 2008
New Revision: 5127
URL: http://svn.gnome.org/viewvc/totem?rev=5127&view=rev

Log:
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.



Modified:
   trunk/ChangeLog
   trunk/src/plugins/youtube/youtube.py

Modified: trunk/src/plugins/youtube/youtube.py
==============================================================================
--- trunk/src/plugins/youtube/youtube.py	(original)
+++ trunk/src/plugins/youtube/youtube.py	Fri Feb 15 11:50:29 2008
@@ -15,8 +15,9 @@
 		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 @@
 
 		self.max_results = 20
 		self.button_down = False
-		self.results_downloaded = True
 
 		self.search_terms = ""
 		self.youtube_id = ""
@@ -33,6 +33,7 @@
 		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 @@
 		"""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)
-
-				self.entry[treeview_name] = None
-				return False
-			else:
-				return True
+			"""Revert the cursor"""
+			window = self.vbox.window
+			window.set_cursor (None)
+
+			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 @@
 		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":



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]