Skip to content

Commit

Permalink
Ensure boto3's managed transfer won't use threads
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Nordhausen committed Feb 14, 2017
1 parent f4ec42a commit fc5c339
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions moto/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
import inspect
import re

try:
import boto3
except ImportError:
boto3 = None
from httpretty import HTTPretty
from .responses import metadata_response
from .utils import convert_regex_to_flask_path


class MockAWS(object):
nested_count = 0
original_create_transfer_manager = None

def __init__(self, backends):
self.backends = backends
Expand Down Expand Up @@ -38,6 +43,15 @@ def start(self, reset=True):
if not HTTPretty.is_enabled():
HTTPretty.enable()

if boto3 and self.__class__.original_create_transfer_manager is None:
boto3.client('s3') # Ensure that boto3.s3 exists.
original_create_transfer_manager = boto3.s3.transfer.create_transfer_manager
self.__class__.original_create_transfer_manager = original_create_transfer_manager
def patched_create_transfer_manager(client, config, *args, **kwargs):
config.use_threads = False
return original_create_transfer_manager(client, config, *args, **kwargs)
boto3.s3.transfer.create_transfer_manager = patched_create_transfer_manager

for method in HTTPretty.METHODS:
backend = list(self.backends.values())[0]
for key, value in backend.urls.items():
Expand All @@ -63,6 +77,9 @@ def stop(self):
if self.__class__.nested_count == 0:
HTTPretty.disable()
HTTPretty.reset()
if boto3:
boto3.s3.transfer.create_transfer_manager = self.__class__.original_create_transfer_manager
self.__class__.original_create_transfer_manager = None

def decorate_callable(self, func, reset):
def wrapper(*args, **kwargs):
Expand Down

0 comments on commit fc5c339

Please sign in to comment.