]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Teach upload deque to be sequential and asynchronous
authorDavid Stainton <dstainton415@gmail.com>
Fri, 17 Apr 2015 19:59:37 +0000 (20:59 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 28 Apr 2015 18:39:37 +0000 (19:39 +0100)
src/allmydata/frontends/drop_upload.py

index 337128976ecd2917007d6028f01827d0df081b6a..75248e55d76b0a76c804dff1fc187c2962be97aa 100644 (file)
@@ -2,7 +2,7 @@
 import sys, os
 from collections import deque
 
-from twisted.internet import defer, reactor
+from twisted.internet import defer, reactor, task
 from twisted.python.failure import Failure
 from twisted.python.filepath import FilePath
 from twisted.application import service
@@ -135,21 +135,22 @@ class DropUploader(service.MultiService):
         processing the upload items...
         """
         self.is_upload_ready = True
-        self._process_deque()
+        self._turn_deque()
 
     def _append_to_deque(self, path):
         self._upload_deque.append(path)
         self._pending.add(path)
         if self.is_upload_ready:
-            reactor.callLater(0, self._process_deque)
-
-    def _process_deque(self):
-        while True:
-            try:
-                path = self._upload_deque.pop()
-                self._process(path)
-            except IndexError:
-                break
+            reactor.callLater(0, self._turn_deque)
+
+    def _turn_deque(self):
+        try:
+            path = self._upload_deque.pop()
+        except IndexError:
+            self._log("magic folder upload deque is now empty")
+            return
+        d = task.deferLater(reactor, 0, self._process, path)
+        d.addCallback(lambda ign: self._turn_deque())
 
     def _notify(self, opaque, path, events_mask):
         self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask))))