From d33ebd60c49ae993d0da5ca715df2e93968c1772 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Mon, 2 Oct 2017 14:52:04 -0400 Subject: [PATCH] fix to not reflect all the files at once --- lbrynet/file_manager/EncryptedFileManager.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lbrynet/file_manager/EncryptedFileManager.py b/lbrynet/file_manager/EncryptedFileManager.py index 9d38548dd..b0f9966a1 100644 --- a/lbrynet/file_manager/EncryptedFileManager.py +++ b/lbrynet/file_manager/EncryptedFileManager.py @@ -25,10 +25,12 @@ log = logging.getLogger(__name__) class EncryptedFileManager(object): - """Keeps track of currently opened LBRY Files, their options, and - their LBRY File specific metadata. - """ + Keeps track of currently opened LBRY Files, their options, and + their LBRY File specific metadata. + """ + # when reflecting files, reflect up to this many files at a time + CONCURRENT_REFLECTS = 5 def __init__(self, session, stream_info_manager, sd_identifier, download_directory=None): @@ -235,13 +237,13 @@ class EncryptedFileManager(object): return l.toggle_running() return defer.fail(Failure(ValueError("Could not find that LBRY file"))) - def _reflect_lbry_files(self): - for lbry_file in self.lbry_files: - yield reflect_stream(lbry_file) - @defer.inlineCallbacks def reflect_lbry_files(self): - yield defer.DeferredList(list(self._reflect_lbry_files())) + sem = defer.DeferredSemaphore(self.CONCURRENT_REFLECTS) + ds = [] + for lbry_file in self.lbry_files: + ds.append(sem.run(reflect_stream, lbry_file)) + yield defer.DeferredList(ds) @defer.inlineCallbacks def stop(self):