-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Load botocore i/o methods in executor #1196
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import asyncio | ||
import functools | ||
|
||
from botocore import UNSIGNED | ||
from botocore import __version__ as botocore_version | ||
from botocore import translate | ||
from botocore.client import logger | ||
from botocore.exceptions import PartialCredentialsError | ||
from botocore.loaders import Loader | ||
from botocore.session import EVENT_ALIASES, ServiceModel | ||
from botocore.session import Session as _SyncSession | ||
from botocore.session import UnknownServiceError, copy | ||
|
@@ -37,6 +42,7 @@ def __init__( | |
event_hooks=None, | ||
include_builtin_handlers=True, | ||
profile=None, | ||
load_executor=False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of this being a bool, you should just pass in the executor you want to use for the loader, that way you avoid defaulting to creating a ton of threads |
||
): | ||
if event_hooks is None: | ||
event_hooks = AioHierarchicalEmitter() | ||
|
@@ -46,6 +52,7 @@ def __init__( | |
) | ||
|
||
self._set_user_agent_for_session() | ||
self.load_executor = load_executor | ||
|
||
def _set_user_agent_for_session(self): | ||
# Mimic approach taken by AWS's aws-cli project | ||
|
@@ -103,9 +110,25 @@ async def get_service_data(self, service_name, api_version=None): | |
Retrieve the fully merged data associated with a service. | ||
""" | ||
data_path = service_name | ||
service_data = self.get_component('data_loader').load_service_model( | ||
data_path, type_name='service-2', api_version=api_version | ||
data_loader: Loader = self.get_component('data_loader') | ||
logger.debug( | ||
"AioSession - Method load_service_model[botocore] could generate I/O. Running in executor: %s", | ||
self.load_executor, | ||
) | ||
Comment on lines
+114
to
117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
if self.load_executor: | ||
service_data = await asyncio.get_event_loop().run_in_executor( | ||
None, | ||
functools.partial( | ||
data_loader.load_service_model, | ||
data_path, | ||
type_name='service-2', | ||
api_version=api_version, | ||
), | ||
) | ||
else: | ||
service_data = data_loader.load_service_model( | ||
data_path, type_name='service-2', api_version=api_version | ||
) | ||
service_id = EVENT_ALIASES.get(service_name, service_name) | ||
await self._events.emit( | ||
f'service-data-loaded.{service_id}', | ||
|
@@ -223,6 +246,7 @@ async def _create_client( | |
client_config=config, | ||
api_version=api_version, | ||
auth_token=auth_token, | ||
load_executor=self.load_executor, | ||
) | ||
monitor = self._get_internal_component('monitor') | ||
if monitor is not None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to add this to the documentation instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed