[3.12] gh-116143: Fix race condition in pydoc _start_server (GH-116144) (#116415)

gh-116143: Fix race condition in pydoc _start_server (GH-116144)
(cherry picked from commit 02ee475ee3)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-03-06 15:58:02 +01:00 committed by GitHub
parent 5c69f60ae1
commit 2528e46470
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -2493,6 +2493,7 @@ def _start_server(urlhandler, hostname, port):
threading.Thread.__init__(self)
self.serving = False
self.error = None
self.docserver = None
def run(self):
"""Start the server."""
@ -2525,9 +2526,9 @@ def _start_server(urlhandler, hostname, port):
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