Skip to content

Commit 1fd1754

Browse files
committed
Merge branch 'ctrlc' into dev
2 parents 7de3224 + 81db675 commit 1fd1754

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

oauth2cli/authcode.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def __init__(self, port=None):
145145
# TODO: But, it would treat "localhost" or "" as IPv4.
146146
# If pressed, we might just expose a family parameter to caller.
147147
self._server = Server((address, port or 0), _AuthCodeHandler)
148+
self._closing = False
148149

149150
def get_port(self):
150151
"""The port this server actually listening to"""
@@ -258,7 +259,8 @@ def _get_auth_response(self, result, auth_uri=None, timeout=None, state=None,
258259

259260
self._server.timeout = timeout # Otherwise its handle_timeout() won't work
260261
self._server.auth_response = {} # Shared with _AuthCodeHandler
261-
while True:
262+
while not self._closing: # Otherwise, the handle_request() attempt
263+
# would yield noisy ValueError trace
262264
# Derived from
263265
# https://docs.python.org/2/library/basehttpserver.html#more-examples
264266
self._server.handle_request()
@@ -271,6 +273,7 @@ def _get_auth_response(self, result, auth_uri=None, timeout=None, state=None,
271273

272274
def close(self):
273275
"""Either call this eventually; or use the entire class as context manager"""
276+
self._closing = True
274277
self._server.server_close()
275278

276279
def __enter__(self):

0 commit comments

Comments
 (0)