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: [asyncio] orphan future close loop and cause "RuntimeError: Event loop stopped before Future completed."
Type: Stage: resolved
Components: asyncio Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, jimmylai, lukasz.langa, yselivanov
Priority: normal Keywords:

Created on 2017-05-21 13:44 by jimmylai, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1688 merged jimmylai, 2017-05-21 13:44
PR 1755 merged lukasz.langa, 2017-05-23 06:09
PR 1758 merged lukasz.langa, 2017-05-23 06:13
PR 3295 merged jimmylai, 2017-09-04 19:56
Messages (2)
msg294102 - (view) Author: Jimmy Lai (jimmylai) * Date: 2017-05-21 13:44
Problem:
"RuntimeError: Event loop stopped before Future completed." throws when calling run_until_complete().

We investigate and find out some orphan futures stay in the event loop before we run another run_until_complete(another_async_func()).
The orphan future has pending state and is attached with _run_until_complete_cb from previous run_until_complete.
It happens because the orphan future thrown Exception and then raise, thus remove_done_callback(_run_until_complete_cb) didn't called.
Move it to finally section can fix it.
With this patch, we stop seeing the Runtime Error.
msg305382 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2017-11-01 13:54
New changeset d1e34031f68a3c7523a5376575c87cd0fea2425c by Andrew Svetlov (jimmylai) in branch 'master':
[asyncio] bpo-30423: add regression test for orphan future causes "RuntimeError: Event loop stopped before Future completed." (#3295)
https://github.com/python/cpython/commit/d1e34031f68a3c7523a5376575c87cd0fea2425c
History
Date User Action Args
2022-04-11 14:58:46adminsetgithub: 74608
2017-11-01 13:54:48asvetlovsetnosy: + asvetlov
messages: + msg305382
2017-09-04 19:56:58jimmylaisetpull_requests: + pull_request3329
2017-05-23 07:37:31lukasz.langasetstatus: open -> closed
stage: resolved
resolution: fixed
versions: + Python 3.5, Python 3.7
2017-05-23 06:13:54lukasz.langasetpull_requests: + pull_request1844
2017-05-23 06:09:51lukasz.langasetpull_requests: + pull_request1842
2017-05-23 05:31:27lukasz.langasetnosy: + lukasz.langa
2017-05-21 13:44:28jimmylaicreate