Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reenables true multithreaded s3 copy #2423

Merged
merged 1 commit into from
Jul 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions luigi/contrib/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import os.path
import warnings

from multiprocessing.pool import ThreadPool

import botocore

try:
Expand Down Expand Up @@ -323,6 +325,9 @@ def copy(self, source_path, destination_path, threads=100, start_time=None, end_
total_keys = 0

if self.isdir(source_path):
copy_jobs = []
management_pool = ThreadPool(processes=threads)

(bucket, key) = self._path_to_bucket_and_key(source_path)
key_path = self._add_path_delimiter(key)
key_path_len = len(key_path)
Expand All @@ -340,8 +345,19 @@ def copy(self, source_path, destination_path, threads=100, start_time=None, end_
'Key': src_prefix + path
}

self.s3.meta.client.copy(
copy_source, dst_bucket, dst_prefix + path, Config=transfer_config, ExtraArgs=kwargs)
the_kwargs = {'Config': transfer_config, 'ExtraArgs': kwargs}
job = management_pool.apply_async(self.s3.meta.client.copy,
args=(copy_source, dst_bucket, dst_prefix + path),
kwds=the_kwargs)
copy_jobs.append(job)

# Wait for the pools to finish scheduling all the copies
management_pool.close()
management_pool.join()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just check that this doesn't have a ContextManager interface maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minutes of Google searching doesn't return valuable resources towards this desire.


# Raise any errors encountered in any of the copy processes
for result in copy_jobs:
result.get()

end = datetime.datetime.now()
duration = end - start
Expand Down