classification
Title: test_asyncio: test_cancel_gather_2() dangling thread
Type: Stage: resolved
Components: Tests Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2019-06-03 01:18 by vstinner, last changed 2019-06-04 12:43 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13779 merged vstinner, 2019-06-03 15:22
PR 13786 merged vstinner, 2019-06-03 20:58
PR 13792 closed asvetlov, 2019-06-03 23:33
Messages (17)
msg344353 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 01:18
s390x RHEL 3.x buildbot:
https://buildbot.python.org/all/#/builders/21/builds/3150

test_cancel_gather_1 (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests)
Ensure that a gathering future refuses to be cancelled once all ... ok
test_cancel_gather_2 (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ...
Warning -- threading_cleanup() failed to cleanup -1 threads (count: 0, dangling: 1)
Dangling thread: <_MainThread(MainThread, started 4396153272064)>
ok

test_cancel_inner_future (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ... ok
test_cancel_task_catching (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ... ok

--


AMD64 FreeBSD 10-STABLE Non-Debug 3.x:
https://buildbot.python.org/all/#/builders/167/builds/1181

test_cancel_gather_2 (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ... Warning -- threading_cleanup() failed to cleanup -1 threads (count: 0, dangling: 1)
msg344358 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 01:26
Another similar error on "ARMv7 Debian buster 3.x" buildbot:
https://buildbot.python.org/all/#/builders/176/builds/664

test_proc_exited (test.test_asyncio.test_subprocess.SubprocessTransportTests) ... Warning -- threading_cleanup() failed to cleanup -1 threads (count: 0, dangling: 1)
msg344359 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 01:28
AMD64 Ubuntu Shared 3.x:
https://buildbot.python.org/all/#/builders/141/builds/1912

test_proc_exited (test.test_asyncio.test_subprocess.SubprocessTransportTests) ... Warning -- threading_cleanup() failed to cleanup -1 threads (count: 0, dangling: 1)
test_close (test.test_asyncio.test_unix_events.SafeChildWatcherTests) ... /srv/buildbot/buildarea/3.x.bolen-ubuntu/build/Lib/asyncio/base_events.py:646: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
  _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
msg344426 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 15:04
https://buildbot.python.org/all/#/builders/167/builds/1188

Variant:

test_cancel_both_task_and_inner_future (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ... ok
test_cancel_current_task (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ... ok
test_cancel_gather_1 (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests)
Ensure that a gathering future refuses to be cancelled once all ... Warning -- threading_cleanup() failed to cleanup -1 threads (count: 0, dangling: 1)
Dangling thread: <_MainThread(MainThread, started 34389124096)>
ok
test_cancel_gather_2 (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ... ok
test_cancel_inner_future (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ... ok
test_cancel_task_catching (test.test_asyncio.test_tasks.CTaskSubclass_PyFuture_Tests) ... ok
msg344427 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 15:16
See also bpo-34037: "asyncio: BaseEventLoop.close() shutdowns the executor without waiting causing leak of dangling threads".
msg344433 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 15:49
New changeset 49a7e347976c9b39149ac7505b11ad6e9e2bdeec by Victor Stinner in branch 'master':
bpo-37137: Fix test_asyncio: use TestCase.set_event_loop() (GH-13779)
https://github.com/python/cpython/commit/49a7e347976c9b39149ac7505b11ad6e9e2bdeec
msg344471 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 20:38
My change didn't fix the issue:

https://buildbot.python.org/all/#/builders/176/builds/680

test_proc_exited (test.test_asyncio.test_subprocess.SubprocessTransportTests) ... Warning -- threading_cleanup() failed to cleanup -1 threads (count: 0, dangling: 1)
msg344479 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 21:32
I push a fix in asyncio, instead of trying to fix individual asyncio tests:

New changeset 0f0a30f4da4b529e0f7df857b9f575b231b32758 by Victor Stinner in branch 'master':
bpo-34037, asyncio: add BaseEventLoop.wait_executor_on_close (GH-13786)
https://github.com/python/cpython/commit/0f0a30f4da4b529e0f7df857b9f575b231b32758

See https://bugs.python.org/issue34037#msg344476
msg344481 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 21:40
My second attempt isn't fully successful :-( test_asyncio still fails with ENV_CHANGED :-(

https://buildbot.python.org/all/#/builders/185/builds/488

test_current_task_no_running_loop_implicit (test.test_asyncio.test_tasks.CCurrentLoopTests) ... Warning -- threading_cleanup() failed to cleanup -1 threads (count: 0, dangling: 1)
msg344488 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-06-03 23:13
I suspect that I've added this dangling thread by https://github.com/python/cpython/blob/master/Lib/asyncio/unix_events.py#L1248-L1251 :(
msg344489 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-06-03 23:27
Working on PR
msg344490 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 23:30
> I suspect that I've added this dangling thread by https://github.com/python/cpython/blob/master/Lib/asyncio/unix_events.py#L1248-L1251 :(

Can you please try to revert commit 13ed07998ad93dbdd94991ba0451b9b559f07972?
msg344491 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-06-03 23:35
We have two options:
1. Apply https://github.com/python/cpython/pull/13792 to wait for dangling threads
2. Revert added watchers entirely

What do you prefer?
msg344492 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-03 23:38
> 2. Revert added watchers entirely

I prefer this option just because we must fix all bugs as soon as possible to get the beta1 released, and this bug is just one bug in a list of bugs.

I might try to help you *later* to fix the change to prevent this bug.
msg344497 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-06-03 23:50
Got you. https://github.com/python/cpython/pull/13793
msg344516 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-04 01:29
Thanks Andrew! Sorry that you had to revert your change :-(

We can reconsider to merge again your change after beta1 (if our release manager is fine with that).
msg344557 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-04 12:43
The initial issue has been fixed.

Let's continue the discussion on https://bugs.python.org/issue35621 to maybe reapply commit 13ed07998ad93dbdd94991ba0451b9b559f07972.
History
Date User Action Args
2019-06-04 12:43:35vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-06-04 12:43:27vstinnersetmessages: + msg344557
2019-06-04 01:29:46vstinnersetmessages: + msg344516
2019-06-03 23:50:23asvetlovsetmessages: + msg344497
2019-06-03 23:38:33vstinnersetmessages: + msg344492
2019-06-03 23:35:06asvetlovsetmessages: + msg344491
2019-06-03 23:33:44asvetlovsetpull_requests: + pull_request13677
2019-06-03 23:30:01vstinnersetmessages: + msg344490
2019-06-03 23:27:57asvetlovsetmessages: + msg344489
2019-06-03 23:13:59asvetlovsetnosy: + asvetlov
messages: + msg344488
2019-06-03 21:40:55vstinnersetmessages: + msg344481
2019-06-03 21:32:26vstinnersetmessages: + msg344479
2019-06-03 20:58:20vstinnersetpull_requests: + pull_request13670
2019-06-03 20:38:32vstinnersetmessages: + msg344471
2019-06-03 15:49:09vstinnersetmessages: + msg344433
2019-06-03 15:22:36vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request13664
2019-06-03 15:16:50vstinnersetmessages: + msg344427
2019-06-03 15:04:03vstinnersetmessages: + msg344426
2019-06-03 01:28:35vstinnersetmessages: + msg344359
2019-06-03 01:26:58vstinnersetmessages: + msg344358
2019-06-03 01:18:08vstinnercreate