Skip to content

Commit 26f7956

Browse files
[3.11] gh-116143: Fix race condition in pydoc _start_server (GH-116144) (#116416)
gh-116143: Fix race condition in pydoc _start_server (GH-116144) (cherry picked from commit 02ee475) Co-authored-by: Itamar Oren <[email protected]>
1 parent d69bef6 commit 26f7956

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Lib/pydoc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,6 +2491,7 @@ def __init__(self, urlhandler, host, port):
24912491
threading.Thread.__init__(self)
24922492
self.serving = False
24932493
self.error = None
2494+
self.docserver = None
24942495

24952496
def run(self):
24962497
"""Start the server."""
@@ -2523,9 +2524,9 @@ def stop(self):
25232524

25242525
thread = ServerThread(urlhandler, hostname, port)
25252526
thread.start()
2526-
# Wait until thread.serving is True to make sure we are
2527-
# really up before returning.
2528-
while not thread.error and not thread.serving:
2527+
# Wait until thread.serving is True and thread.docserver is set
2528+
# to make sure we are really up before returning.
2529+
while not thread.error and not (thread.serving and thread.docserver):
25292530
time.sleep(.01)
25302531
return thread
25312532

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a race in pydoc ``_start_server``, eliminating a window in which
2+
``_start_server`` can return a thread that is "serving" but without a
3+
``docserver`` set.

0 commit comments

Comments
 (0)