8000 gh-116143: Fix race condition in pydoc _start_server by itamaro · Pull Request #116144 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-116143: Fix race condition in pydoc _start_server #116144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-116143: Fix race condition in pydoc _start_server
  • Loading branch information
itamaro committed Feb 29, 2024
commit 9afa6c5aa7c990f22136518e9f972c908b8f7bb9
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