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: test_os.TestSendfile.test_keywords() leaks dangling threads
Type: resource usage Stage: resolved
Components: Tests Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2017-07-12 13:26 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2680 merged vstinner, 2017-07-12 13:42
PR 2844 merged vstinner, 2017-07-24 13:51
PR 2845 merged vstinner, 2017-07-24 13:52
Messages (8)
msg298217 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-12 13:26
The test_keywords() test of test_os.TestSendfile emits a warning about dangling threads:

haypo@selma$ ./python -m test --fail-env-changed -R 3:3 test_os -m test.test_os.TestSendfile.test_keywords
Run tests sequentially
0:00:00 load avg: 0.53 [1/1] test_os
Warning -- threading_cleanup() failed to cleanup 0 threads after 3 sec (count: 0, dangling: 2)
beginning 6 repetitions
123456
Warning -- threading_cleanup() failed to cleanup 0 threads after 3 sec (count: 0, dangling: 2)
.Warning -- threading_cleanup() failed to cleanup 0 threads after 3 sec (count: 0, dangling: 2)
.Warning -- threading_cleanup() failed to cleanup 0 threads after 3 sec (count: 0, dangling: 2)
.Warning -- threading_cleanup() failed to cleanup 0 threads after 3 sec (count: 0, dangling: 2)
.Warning -- threading_cleanup() failed to cleanup 0 threads after 3 sec (count: 0, dangling: 2)
.Warning -- threading_cleanup() failed to cleanup 0 threads after 3 sec (count: 0, dangling: 2)
.
test_os failed (env changed)

1 test altered the execution environment:
    test_os

Total duration: 21 sec
Tests result: ENV CHANGED
msg298219 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-12 13:46
This isn't specific to test_keywords. Dangling threads occurred even if replace the test body with just "return". This is caused by setUp/tearDown or setUpClass/tearDownClass.
msg298220 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-12 13:47
> This isn't specific to test_keywords. Dangling threads occurred even if replace the test body with just "return". This is caused by setUp/tearDown or setUpClass/tearDownClass.

Right, see my PR #2680. The general problem is that tearDownClass() seems to be called while the test case instance is still alive and so didn't clear its attributes. But I wrote a single line fix instead of trying to fix unittest or regrtest :-)
msg298221 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-12 14:05
New changeset d1cc037d1442cc35d1b194ec8e50901514360949 by Victor Stinner in branch 'master':
bpo-30908: Fix dangling thread in test_os.TestSendfile (#2680)
https://github.com/python/cpython/commit/d1cc037d1442cc35d1b194ec8e50901514360949
msg298224 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-12 15:12
The alternate solution is to remove all references to test instances before calling tearDownClass().

Interesting, that this warning is occurred only in the leak hunting mode. In normal cases test instances are removed from a testsuite, but regrtest hacks unittest and disables this in the leak hunting mode (see the line "unittest.BaseTestSuite._cleanup = False" in Lib/test/libregrtest/setup.py). See issue11798.
msg298971 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-24 13:55
Serhiy Storchaka: If you would like to enhance the unittest module, please open a new issue. I prefer to keep this one for the very specific test_os bug.
msg298983 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-24 15:40
New changeset 157b6ad677b7b330d30b2bb5ffbb2edac77b78cb by Victor Stinner in branch '3.5':
bpo-30908: Fix dangling thread in test_os.TestSendfile (#2680) (#2845)
https://github.com/python/cpython/commit/157b6ad677b7b330d30b2bb5ffbb2edac77b78cb
msg298984 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-24 15:40
New changeset bb33ccfc5a216eff753b10a8dc59ec0277f1e1fb by Victor Stinner in branch '3.6':
bpo-30908: Fix dangling thread in test_os.TestSendfile (#2680) (#2844)
https://github.com/python/cpython/commit/bb33ccfc5a216eff753b10a8dc59ec0277f1e1fb
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 75091
2017-07-26 00:12:46vstinnersetstatus: open -> closed
stage: resolved
resolution: fixed
versions: + Python 3.5, Python 3.6
2017-07-24 15:40:52vstinnersetmessages: + msg298984
2017-07-24 15:40:52vstinnersetmessages: + msg298983
2017-07-24 13:55:27vstinnersetmessages: + msg298971
2017-07-24 13:52:17vstinnersetpull_requests: + pull_request2889
2017-07-24 13:51:16vstinnersetpull_requests: + pull_request2888
2017-07-12 15:12:18serhiy.storchakasetmessages: + msg298224
2017-07-12 14:05:45vstinnersetmessages: + msg298221
2017-07-12 13:47:50vstinnersetmessages: + msg298220
2017-07-12 13:46:22serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg298219
2017-07-12 13:42:06vstinnersetpull_requests: + pull_request2746
2017-07-12 13:26:16vstinnercreate