dvc: introduce --jobs option and use map_progress

It replaces POOL_SIZE constant and by default equals to the
number of cpus available.

map_progress is a helper for 'sync' and 'import' commands to
run in a multi-threaded mode.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2017-06-25 04:04:19 +03:00
parent 7c6765c196
commit 76db9db5c2
4 changed files with 20 additions and 14 deletions
+2 -7
View File
@@ -6,9 +6,7 @@ from dvc.exceptions import DvcException
from dvc.runtime import Runtime
from dvc.system import System
from dvc.data_cloud import DataCloud
from dvc.progress import progress
POOL_SIZE = 4
from dvc.utils import map_progress
class DataSyncError(DvcException):
@@ -29,7 +27,6 @@ class CmdDataSync(CmdBase):
def run(self):
with DvcLock(self.is_locker, self.git):
cloud = DataCloud(self.settings)
pool = ThreadPool(processes=POOL_SIZE)
targets = []
if len(self.parsed_args.targets) == 0:
@@ -45,9 +42,7 @@ class CmdDataSync(CmdBase):
else:
raise DataSyncError('File "{}" does not exit'.format(target))
progress.set_n_total(len(targets))
pool.map(cloud.sync, targets)
progress.finish()
map_progress(cloud.sync, targets, self.parsed_args.jobs)
pass
if __name__ == '__main__':