This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pydoc: ServerThread.stop() leaves a dangling thread
Type: resource usage Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, vstinner
Priority: normal Keywords:

Created on 2017-08-18 23:50 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3151 merged vstinner, 2017-08-18 23:51
PR 3177 closed vstinner, 2017-08-22 09:57
PR 7324 merged vstinner, 2018-06-01 16:07
Messages (5)
msg300556 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-18 23:50
When using https://github.com/python/cpython/pull/3138 I see that test_pydoc leaves a dangling thread. The bug comes from test_server() which uses pydoc ServerThread.

ServerThread.stop() and test_pydoc don't join the thread. Moreover, ServerThread.docserver has a reference cycle through the DocServer.callback attribute.

Attached PR modifies ServerThread.stop() to join itself (the thread), to wait until the HTTP server completes, and then explicitly break the reference cycle.

With the PR, pydoc may hang if a bad HTTP client. So another option is to only modify test_pydoc to join() + break the ref cycle.
msg300557 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-18 23:52
This issue is similar to bpo-31151: socketserver ForkingMixIn.server_close() leaks zombie processes.
msg300652 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-21 21:24
New changeset 4cab2cd0c05fcda5fcb128c9eb230253fff88c21 by Victor Stinner in branch 'master':
bpo-31238: pydoc ServerThread.stop() now joins itself (#3151)
https://github.com/python/cpython/commit/4cab2cd0c05fcda5fcb128c9eb230253fff88c21
msg300701 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-22 14:57
I left Python 2.7 and 3.6 unchanged to focus on fixing dangling threads and other similar bugs in the master branch first. I will see later if we really need to backport the fix to stable branches. In the meanwhile, I close the issue.
msg318439 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-01 17:39
New changeset f3297433e309e9591eaa3f36e1d7887e9d0620d7 by Victor Stinner in branch '3.6':
bpo-31238: pydoc ServerThread.stop() now joins itself (GH-3151) (GH-7324)
https://github.com/python/cpython/commit/f3297433e309e9591eaa3f36e1d7887e9d0620d7
History
Date User Action Args
2022-04-11 14:58:50adminsetgithub: 75421
2018-06-01 17:39:19vstinnersetmessages: + msg318439
2018-06-01 16:07:41vstinnersetpull_requests: + pull_request6953
2017-08-22 14:57:00vstinnersetmessages: + msg300701
2017-08-22 14:55:52vstinnersetstatus: open -> closed
resolution: fixed
stage: resolved
2017-08-22 09:57:15vstinnersetpull_requests: + pull_request3215
2017-08-21 21:24:42vstinnersetmessages: + msg300652
2017-08-21 17:37:33serhiy.storchakasetnosy: + pitrou
2017-08-18 23:52:39vstinnersetmessages: + msg300557
2017-08-18 23:51:09vstinnersetpull_requests: + pull_request3185
2017-08-18 23:50:45vstinnercreate