https://github.com/python/cpython/commit/26f7956f8fe83a07c012e2663ede6d706997a901 commit: 26f7956f8fe83a07c012e2663ede6d706997a901 branch: 3.11 author: Miss Islington (bot) <[email protected]> committer: carljm <[email protected]> date: 2024-03-06T15:07:08Z summary:
[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 <[email protected]> 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 56a47dc68a6663..a8cfeaf925fdce 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -2491,6 +2491,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.""" @@ -2523,9 +2524,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]
