[conduit: 54/138] Don't use threading.Event to block the metadata discover process



commit 9b8e57ef09ab0a3131837c731f40a6cd8ba5db43
Author: John Carr <john carr unrouted co uk>
Date:   Thu Apr 30 04:01:22 2009 -0700

    Don't use threading.Event to block the metadata discover process
---
 conduit/utils/Makefile.am  |    3 ++-
 conduit/utils/MediaFile.py |   10 ++++------
 conduit/utils/Wait.py      |   14 ++++++++++++++
 test/soup/modules/ipod.py  |   10 +++++-----
 4 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/conduit/utils/Makefile.am b/conduit/utils/Makefile.am
index 99c23a7..a84e02a 100644
--- a/conduit/utils/Makefile.am
+++ b/conduit/utils/Makefile.am
@@ -5,7 +5,8 @@ conduit_PYTHON = \
 	Memstats.py 				\
 	MediaFile.py 				\
 	CommandLineConverter.py		\
-	Singleton.py
+	Singleton.py				\
+	Wait.py
 
 clean-local:
 	rm -rf *.pyc *.pyo
diff --git a/conduit/utils/MediaFile.py b/conduit/utils/MediaFile.py
index 0377d25..2d09e7e 100644
--- a/conduit/utils/MediaFile.py
+++ b/conduit/utils/MediaFile.py
@@ -1,6 +1,7 @@
 import threading
 import conduit
 import conduit.datatypes.File as File
+import conduit.utils.Wait as Wait
 import logging
 log = logging.getLogger("datatypes.Audio")
 
@@ -53,19 +54,16 @@ class MediaFile(File.File):
         This is also a very expensive operation, should be called only when 
         necessary.   
         '''
-        event = threading.Event()
+        blocker = Wait.WaitOnSignal()
         def discovered(discoverer, valid):
             self._valid = valid
-            event.set()
+            blocker.unblock()
         # FIXME: Using Discoverer for now, but we should switch to utils.GstMetadata
         #        when we get it to work (and eventually support thumbnails).
         info = gst.extend.discoverer.Discoverer(self.get_local_uri())
         info.connect('discovered', discovered)
         info.discover()
-        # Wait for discover to finish (which is async and emits discovered)
-        # This thread MUST NOT be the mainloop thread, because then the signal
-        # will NEVER be received, and this will deadlock.
-        event.wait()
+        blocker.block()
         if self._valid:
             tags = info.tags
         else:
diff --git a/conduit/utils/Wait.py b/conduit/utils/Wait.py
new file mode 100644
index 0000000..c868c52
--- /dev/null
+++ b/conduit/utils/Wait.py
@@ -0,0 +1,14 @@
+import glib
+
+class WaitOnSignal(object):
+
+    def __init__(self):
+        self.context = glib.MainContext()
+        self.loop = glib.MainLoop()
+
+    def block(self):
+        self.loop.run()
+
+    def unblock(self):
+        self.loop.quit()
+
diff --git a/test/soup/modules/ipod.py b/test/soup/modules/ipod.py
index f16a060..56ef352 100644
--- a/test/soup/modules/ipod.py
+++ b/test/soup/modules/ipod.py
@@ -55,11 +55,11 @@ class iPodPhoto(soup.modules.ModuleWrapper):
         return iPodModule.IPodPhotoSink(self.folder, "")
 
 
-#class iPodMusic(soup.modules.ModuleWrapper):
+class iPodMusic(soup.modules.ModuleWrapper):
 
-#    dataclass = MusicWrapper
+    dataclass = MusicWrapper
 
-#    def create_dataprovider(self):
-#        self.folder = create_fake_ipod()
-#        return iPodModule.IPodMusicTwoWay(self.folder, "")
+    def create_dataprovider(self):
+        self.folder = create_fake_ipod()
+        return iPodModule.IPodMusicTwoWay(self.folder, "")
 



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