Stop leaking threads

pull/22373/head
Richard Belleville 5 years ago
parent 6e69d0da9f
commit 59b040d3c4
  1. 11
      src/python/grpcio/grpc/_auth.py

@ -40,9 +40,10 @@ def _create_get_token_callback(callback):
class GoogleCallCredentials(grpc.AuthMetadataPlugin):
"""Metadata wrapper for GoogleCredentials from the oauth2client library."""
_THREAD_POOL = futures.ThreadPoolExecutor()
def __init__(self, credentials):
self._credentials = credentials
self._pool = futures.ThreadPoolExecutor(max_workers=1)
# Hack to determine if these are JWT creds and we need to pass
# additional_claims when getting a token
@ -52,16 +53,14 @@ class GoogleCallCredentials(grpc.AuthMetadataPlugin):
def __call__(self, context, callback):
# MetadataPlugins cannot block (see grpc.beta.interfaces.py)
if self._is_jwt:
future = self._pool.submit(
future = self._THREAD_POOL.submit(
self._credentials.get_access_token,
additional_claims={'aud': context.service_url})
else:
future = self._pool.submit(self._credentials.get_access_token)
future = self._THREAD_POOL.submit(
self._credentials.get_access_token)
future.add_done_callback(_create_get_token_callback(callback))
def __del__(self):
self._pool.shutdown(wait=False)
class AccessTokenAuthMetadataPlugin(grpc.AuthMetadataPlugin):
"""Metadata wrapper for raw access token credentials."""

Loading…
Cancel
Save