https://github.com/python/cpython/commit/02ee475ee3ce9468d44758df2cd79df9f0926303
commit: 02ee475ee3ce9468d44758df2cd79df9f0926303
branch: main
author: Itamar Oren <[email protected]>
committer: carljm <[email protected]>
date: 2024-03-06T07:39:51-07:00
summary:
gh-116143: Fix race condition in pydoc _start_server (#116144)
files:
A Misc/NEWS.d/next/Library/2024-03-05-20-53-34.gh-issue-116143.sww6Zl.rst
M Lib/pydoc.py
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 407c0205c7ab66..08fd7aba7c9472 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -2504,6 +2504,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."""
@@ -2536,9 +2537,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
diff --git
a/Misc/NEWS.d/next/Library/2024-03-05-20-53-34.gh-issue-116143.sww6Zl.rst
b/Misc/NEWS.d/next/Library/2024-03-05-20-53-34.gh-issue-116143.sww6Zl.rst
new file mode 100644
index 00000000000000..07aa312ee25f3b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-03-05-20-53-34.gh-issue-116143.sww6Zl.rst
@@ -0,0 +1,3 @@
+Fix a race in pydoc ``_start_server``, eliminating a window in which
+``_start_server`` can return a thread that is "serving" but without a
+``docserver`` set.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]