summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-03-06 15:07:08 (GMT)
committerGitHub <noreply@github.com>2024-03-06 15:07:08 (GMT)
commit26f7956f8fe83a07c012e2663ede6d706997a901 (patch)
tree084a77ab003404f307728731dd6463a4839ccbe9 /Lib/pydoc.py
parentd69bef60803b43544d67c8b35117ddf483c5732b (diff)
downloadcpython-26f7956f8fe83a07c012e2663ede6d706997a901.zip
cpython-26f7956f8fe83a07c012e2663ede6d706997a901.tar.gz
cpython-26f7956f8fe83a07c012e2663ede6d706997a901.tar.bz2
[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 02ee475ee3ce9468d44758df2cd79df9f0926303) Co-authored-by: Itamar Oren <itamarost@gmail.com>
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-xLib/pydoc.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 56a47dc..a8cfeaf 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -2491,6 +2491,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."""
@@ -2523,9 +2524,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