@@ -51,14 +51,22 @@ class AuthMetadataPlugin(grpc.AuthMetadataPlugin):
51
51
object used to refresh credentials as needed.
52
52
"""
53
53
54
+ # Python 2.7 has no default for max_workers.
55
+ # In Python >= 3.5, ThreadPoolExecutor defaults to the
56
+ # number of processors on the machine, multiplied by 5.
57
+ if six .PY2 : # pragma: NO COVER
58
+ max_workers = 5
59
+ else :
60
+ max_workers = None
61
+ _AUTH_THREAD_POOL = futures .ThreadPoolExecutor (max_workers = max_workers )
62
+
54
63
def __init__ (self , credentials , request ):
55
64
# pylint: disable=no-value-for-parameter
56
65
# pylint doesn't realize that the super method takes no arguments
57
66
# because this class is the same name as the superclass.
58
67
super (AuthMetadataPlugin , self ).__init__ ()
59
68
self ._credentials = credentials
60
69
self ._request = request
61
- self ._pool = futures .ThreadPoolExecutor (max_workers = 1 )
62
70
63
71
def _get_authorization_headers (self , context ):
64
72
"""Gets the authorization headers for a request.
@@ -89,12 +97,9 @@ def __call__(self, context, callback):
89
97
callback (grpc.AuthMetadataPluginCallback): The callback that will
90
98
be invoked to pass in the authorization metadata.
91
99
"""
92
- future = self ._pool .submit (self ._get_authorization_headers , context )
100
+ future = self ._AUTH_THREAD_POOL .submit (self ._get_authorization_headers , context )
93
101
future .add_done_callback (self ._callback_wrapper (callback ))
94
102
95
- def __del__ (self ):
96
- self ._pool .shutdown (wait = False )
97
-
98
103
99
104
def secure_authorized_channel (
100
105
credentials ,
0 commit comments