Browse code

Support for non-threaded multipart upload

Don't create thread-pool with Config().multipart_num_threads=1.

Michal Ludvig authored on 2012/01/02 20:37:13
Showing 1 changed files
... ...
@@ -81,7 +81,11 @@ class MultiPartUpload(object):
81 81
 
82 82
         chunk_size = max(self.MIN_CHUNK_SIZE, chunk_size)
83 83
         id = 1
84
-        pool = ThreadPool(num_threads)
84
+        if num_threads > 1:
85
+            debug("MultiPart: Uploading in %d threads" % num_threads)
86
+            pool = ThreadPool(num_threads)
87
+        else:
88
+            debug("MultiPart: Uploading in a single thread")
85 89
 
86 90
         while True:
87 91
             if id == self.MAX_CHUNKS:
... ...
@@ -90,11 +94,15 @@ class MultiPartUpload(object):
90 90
                 data = self.file.read(chunk_size)
91 91
             if not data:
92 92
                 break
93
-            pool.add_task(self.upload_part, data, id)
93
+            if num_threads > 1:
94
+                pool.add_task(self.upload_part, data, id)
95
+            else:
96
+                self.upload_part(data, id)
94 97
             id += 1
95 98
 
96
-        debug("Thread pool with %i threads and %i tasks awaiting completion." % (num_threads, id))
97
-        pool.wait_completion()
99
+        if num_threads > 1:
100
+            debug("Thread pool with %i threads and %i tasks awaiting completion." % (num_threads, id))
101
+            pool.wait_completion()
98 102
 
99 103
     def upload_part(self, data, id):
100 104
         """