mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[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 02ee475ee3
)
Co-authored-by: Itamar Oren <itamarost@gmail.com>
This commit is contained in:
parent
d69bef6080
commit
26f7956f8f
2 changed files with 7 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue