Document DownloadPipeline.unpack_many precautions

This commit is contained in:
Marian Beermann 2016-08-18 16:23:36 +02:00
parent 8268e26c6b
commit b46713224b
2 changed files with 14 additions and 5 deletions

View File

@ -99,6 +99,15 @@ class DownloadPipeline:
self.key = key self.key = key
def unpack_many(self, ids, filter=None, preload=False): def unpack_many(self, ids, filter=None, preload=False):
"""
Return iterator of items.
*ids* is a chunk ID list of an item stream. *filter* is a callable
to decide whether an item will be yielded. *preload* preloads the data chunks of every yielded item.
Warning: if *preload* is True then all data chunks of every yielded item have to be retrieved,
otherwise preloaded chunks will accumulate in RemoteRepository and create a memory leak.
"""
unpacker = msgpack.Unpacker(use_list=False) unpacker = msgpack.Unpacker(use_list=False)
for data in self.fetch_many(ids): for data in self.fetch_many(ids):
unpacker.feed(data) unpacker.feed(data)

View File

@ -1329,11 +1329,11 @@ class RemoteArchiverTestCase(ArchiverTestCase):
def test_strip_components_doesnt_leak(self): def test_strip_components_doesnt_leak(self):
self.cmd('init', self.repository_location) self.cmd('init', self.repository_location)
self.create_regular_file('dir/file', contents=b"test file contents 123") self.create_regular_file('dir/file', contents=b"test file contents 1")
self.create_regular_file('dir/file2', contents=b"test file contents 345") self.create_regular_file('dir/file2', contents=b"test file contents 2")
self.create_regular_file('skipped', contents=b"test file contents 567") self.create_regular_file('skipped-file1', contents=b"test file contents 3")
self.create_regular_file('skipped2', contents=b"test file contentsasdasd") self.create_regular_file('skipped-file2', contents=b"test file contents 4")
self.create_regular_file('skipped4', contents=b"sdfdsgdgfhttztu") self.create_regular_file('skipped-file3', contents=b"test file contents 5")
self.cmd('create', self.repository_location + '::test', 'input') self.cmd('create', self.repository_location + '::test', 'input')
marker = 'cached responses left in RemoteRepository' marker = 'cached responses left in RemoteRepository'
with changedir('output'): with changedir('output'):