---
 yum/__init__.py |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/yum/__init__.py b/yum/__init__.py
index 5d268a7..7b2483f 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -90,6 +90,7 @@ import StringIO
 from weakref import proxy as weakref
 
 from urlgrabber.grabber import default_grabber
+from thread import allocate_lock, start_new_thread
 
 __version__ = '3.4.2'
 __version_info__ = tuple([ int(num) for num in __version__.split('.')])
@@ -1970,7 +1971,6 @@ class YumBase(depsolve.Depsolve):
             if (self.conf.cache or repo_cached) and errors:
                 return errors
                 
-
         remote_pkgs.sort(mediasort)
         #  This is kind of a hack and does nothing in non-Fedora versions,
         # we'll fix it one way or anther soon.
@@ -1978,9 +1978,12 @@ class YumBase(depsolve.Depsolve):
             len(remote_pkgs) > 1):
             urlgrabber.progress.text_meter_total_size(remote_size)
         beg_download = time.time()
+        done_repos = set()
+
         i = [0]
         local_size = [0]
-        done_repos = set()
+        lock = allocate_lock() # protects 'i' and 'local_size'
+
         def download(po, i):
             local = po.localPkg()
             checkfunc = (self.verifyPkg, (po, 1), {})
@@ -2005,10 +2008,12 @@ class YumBase(depsolve.Depsolve):
                                    text=text,
                                    cache=po.repo.http_caching != 'none',
                                    )
+                lock.acquire()
                 local_size[0] += po.size
                 if hasattr(urlgrabber.progress, 'text_meter_total_size'):
                     urlgrabber.progress.text_meter_total_size(remote_size,
                                                               local_size[0])
+                lock.release()
                 if po.repoid not in done_repos:
                     #  Check a single package per. repo. ... to give a hint to
                     # the user on big downloads.
@@ -2023,12 +2028,25 @@ class YumBase(depsolve.Depsolve):
                 po.localpath = mylocal
                 if po in errors:
                     del errors[po]
-        def thread():
+
+        def thread(signal):
             while 1:
-                j = i[0]; i[0] += 1
+                lock.acquire(); j = i[0]; i[0] += 1
+                lock.release()
                 if j >= len(remote_pkgs): break
                 download(remote_pkgs[j], j + 1)
-        thread()
+            signal()
+
+        # create N-1 background threads
+        eols = []
+        for n in range(1, self.conf.parallel):
+            eol = allocate_lock(); eol.acquire()
+            start_new_thread(thread, (eol.release,))
+            eols.append(eol)
+
+        # +1, then join background threads
+        thread(lambda: None)
+        for eol in eols: eol.acquire()
 
         if hasattr(urlgrabber.progress, 'text_meter_total_size'):
             urlgrabber.progress.text_meter_total_size(0)
-- 
1.7.4.4

_______________________________________________
Yum-devel mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum-devel

Reply via email to