Skip to content

Commit

Permalink
pythongh-116143: Fix race condition in pydoc _start_server
Browse files Browse the repository at this point in the history
  • Loading branch information
itamaro committed Feb 29, 2024
1 parent 0656509 commit 9afa6c5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 9afa6c5

Please sign in to comment.