diff --git a/Lib/pydoc.py b/Lib/pydoc.py index b0193b4a85164a..7ea52e2817281f 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -2495,6 +2495,7 @@ def __init__(self, urlhandler, host, port): threading.Thread.__init__(self) self.serving = False self.error = None + self.docserver = None def run(self): """Start the server.""" @@ -2527,9 +2528,9 @@ def stop(self): thread = ServerThread(urlhandler, hostname, port) thread.start() - # Wait until thread.serving is True to make sure we are - # really up before returning. - while not thread.error and not thread.serving: + # Wait until thread.serving is True and thread.docserver is set + # to make sure we are really up before returning. + while not thread.error and not (thread.serving and thread.docserver): time.sleep(.01) return thread