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

Remove use of multiprocessing from the OAuth client #2626

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
27 changes: 11 additions & 16 deletions flytekit/clients/auth/auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from http import HTTPStatus as _StatusCodes
from multiprocessing import get_context
from urllib.parse import urlencode as _urlencode
from queue import Queue

import click
import requests
Expand Down Expand Up @@ -124,7 +125,7 @@ def __init__(
request_handler_class: typing.Type[_BaseHTTPServer.BaseHTTPRequestHandler],
bind_and_activate: bool = True,
redirect_path: str = None,
queue: multiprocessing.Queue = None,
queue: Queue = None,
):
_BaseHTTPServer.HTTPServer.__init__(self, server_address, request_handler_class, bind_and_activate)
self._redirect_path = redirect_path
Expand All @@ -142,9 +143,8 @@ def remote_metadata(self) -> EndpointMetadata:

def handle_authorization_code(self, auth_code: str):
self._queue.put(auth_code)
self.server_close()

def handle_request(self, queue: multiprocessing.Queue = None) -> typing.Any:
def handle_request(self, queue: Queue = None) -> typing.Any:
self._queue = queue
return super().handle_request()

Expand Down Expand Up @@ -345,26 +345,21 @@ def get_creds_from_remote(self) -> Credentials:
retrieve credentials
"""
# In the absence of globally-set token values, initiate the token request flow
ctx = get_context("fork")
q = ctx.Queue()
q = Queue()

# First prepare the callback server in the background
server = self._create_callback_server()

server_process = ctx.Process(target=server.handle_request, args=(q,))
server_process.daemon = True
self._request_authorization_code()

try:
server_process.start()
server.handle_request(q)
server.server_close()

# Send the call to request the authorization code in the background
self._request_authorization_code()
# Send the call to request the authorization code in the background

# Request the access token once the auth code has been received.
auth_code = q.get()
return self._request_access_token(auth_code)
finally:
server_process.terminate()
# Request the access token once the auth code has been received.
auth_code = q.get()
return self._request_access_token(auth_code)

def refresh_access_token(self, credentials: Credentials) -> Credentials:
if credentials.refresh_token is None:
Expand Down
Loading