diff options
author | Victor Shyba <victor1984@riseup.net> | 2017-10-25 22:52:34 -0300 |
---|---|---|
committer | Victor Shyba <victor1984@riseup.net> | 2017-10-27 16:01:48 -0300 |
commit | f4ab4e15ba2fd6eb06bcd71e8fe04abc903d4ff0 (patch) | |
tree | 2a639c16d702250e33a4612432fb4892af2aaf71 /src/leap/soledad/client | |
parent | 5faf22e4603d8130d11890f43f2f002821e8a976 (diff) |
[refactor] semaphore.run instead acquire/release
Diffstat (limited to 'src/leap/soledad/client')
-rw-r--r-- | src/leap/soledad/client/_db/blobs/sync.py | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/src/leap/soledad/client/_db/blobs/sync.py b/src/leap/soledad/client/_db/blobs/sync.py index d2b7bed6..a1b5cc4c 100644 --- a/src/leap/soledad/client/_db/blobs/sync.py +++ b/src/leap/soledad/client/_db/blobs/sync.py @@ -78,18 +78,12 @@ class BlobsSynchronizer(object): deferreds = [] semaphore = defer.DeferredSemaphore(self.concurrent_transfers_limit) - def release(result): - print result - semaphore.release() - return result - for i in xrange(total): - yield semaphore.acquire() blob_id = missing.pop() - d = with_retry(self.__send_one, blob_id, namespace, i, total) - d.addCallbacks(release, release) + d = semaphore.run( + with_retry, self.__send_one, blob_id, namespace, i, total) deferreds.append(d) - yield defer.gatherResults(deferreds) + yield defer.gatherResults(deferreds, consumeErrors=True) @defer.inlineCallbacks def __send_one(self, blob_id, namespace, i, total): @@ -127,18 +121,12 @@ class BlobsSynchronizer(object): deferreds = [] semaphore = defer.DeferredSemaphore(self.concurrent_transfers_limit) - def release(result): - semaphore.release() - return result - for i in xrange(len(docs_we_want)): - yield semaphore.acquire() blob_id = docs_we_want.pop() logger.info("Fetching blob (%d/%d): %s" % (i, total, blob_id)) - d = with_retry(self.get, blob_id, namespace) - d.addCallbacks(release, release) + d = semaphore.run(with_retry, self.get, blob_id, namespace) deferreds.append(d) - yield defer.gatherResults(deferreds) + yield defer.gatherResults(deferreds, consumeErrors=True) @defer.inlineCallbacks def sync(self, namespace=''): |