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

fix: make ThreadPoolExecutor a class var #461

Merged
merged 5 commits into from
Mar 19, 2020
Merged
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions google/auth/transport/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ class AuthMetadataPlugin(grpc.AuthMetadataPlugin):
object used to refresh credentials as needed.
"""

_AUTH_THREAD_POOL = futures.ThreadPoolExecutor()

def __init__(self, credentials, request):
# pylint: disable=no-value-for-parameter
# pylint doesn't realize that the super method takes no arguments
# because this class is the same name as the superclass.
super(AuthMetadataPlugin, self).__init__()
self._credentials = credentials
self._request = request
self._pool = futures.ThreadPoolExecutor(max_workers=1)

def _get_authorization_headers(self, context):
"""Gets the authorization headers for a request.
Expand Down Expand Up @@ -84,12 +85,9 @@ def __call__(self, context, callback):
callback (grpc.AuthMetadataPluginCallback): The callback that will
be invoked to pass in the authorization metadata.
"""
future = self._pool.submit(self._get_authorization_headers, context)
future = self._AUTH_THREAD_POOL.submit(self._get_authorization_headers, context)
future.add_done_callback(self._callback_wrapper(callback))

def __del__(self):
self._pool.shutdown(wait=False)


def secure_authorized_channel(
credentials, request, target, ssl_credentials=None, **kwargs
Expand Down