Skip to content

Commit 02ee475

Browse files
authored
gh-116143: Fix race condition in pydoc _start_server (#116144)
1 parent e800265 commit 02ee475

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
@@ -2504,6 +2504,7 @@ def __init__(self, urlhandler, host, port):
25042504
threading.Thread.__init__(self)
25052505
self.serving = False
25062506
self.error = None
2507+
self.docserver = None
25072508

25082509
def run(self):
25092510
"""Start the server."""
@@ -2536,9 +2537,9 @@ def stop(self):
25362537

25372538
thread = ServerThread(urlhandler, hostname, port)
25382539
thread.start()
2539-
# Wait until thread.serving is True to make sure we are
2540-
# really up before returning.
2541-
while not thread.error and not thread.serving:
2540+
# Wait until thread.serving is True and thread.docserver is set
2541+
# to make sure we are really up before returning.
2542+
while not thread.error and not (thread.serving and thread.docserver):
25422543
time.sleep(.01)
25432544
return thread
25442545

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)