-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'oauth2cli/dev' into ctrlc
- Loading branch information
Showing
1 changed file
with
4 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,7 @@ def __init__(self, port=None): | |
# TODO: But, it would treat "localhost" or "" as IPv4. | ||
# If pressed, we might just expose a family parameter to caller. | ||
self._server = Server((address, port or 0), _AuthCodeHandler) | ||
self._closing = False | ||
|
||
def get_port(self): | ||
"""The port this server actually listening to""" | ||
|
@@ -258,7 +259,8 @@ def _get_auth_response(self, result, auth_uri=None, timeout=None, state=None, | |
|
||
self._server.timeout = timeout # Otherwise its handle_timeout() won't work | ||
self._server.auth_response = {} # Shared with _AuthCodeHandler | ||
while True: | ||
while not self._closing: # Otherwise, the handle_request() attempt | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rayluo
Author
Collaborator
|
||
# would yield noisy ValueError trace | ||
# Derived from | ||
# https://docs.python.org/2/library/basehttpserver.html#more-examples | ||
self._server.handle_request() | ||
|
@@ -271,6 +273,7 @@ def _get_auth_response(self, result, auth_uri=None, timeout=None, state=None, | |
|
||
def close(self): | ||
"""Either call this eventually; or use the entire class as context manager""" | ||
self._closing = True | ||
self._server.server_close() | ||
|
||
def __enter__(self): | ||
|
Unfortunately, this is not a watertight solution. Consider when this line (L262) evaluates to
True
but the main thread closes the socket after this line is executed. L266 will then fail withValueError
. Using try except statements (#405) is a better solution according to Python's Easier to ask for forgiveness than permission principal.Some discussion on Stack Overflow: https://stackoverflow.com/questions/1586648/race-condition-creating-folder-in-python