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: IsolatedAsyncioTestCase freezes when exception is raised
Type: crash Stage: resolved
Components: asyncio Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, fornellas, lisroach, miss-islington, r3owen, yselivanov
Priority: normal Keywords: patch

Created on 2019-12-19 19:44 by fornellas, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22654 merged lisroach, 2020-10-11 21:41
PR 22988 merged miss-islington, 2020-10-26 16:28
PR 22989 merged miss-islington, 2020-10-26 16:28
Messages (5)
msg358690 - (view) Author: Fabio Pugliese Ornellas (fornellas) Date: 2019-12-19 19:44
IsolatedAsyncioTestCase freezes whenever an exception that inherits from BaseException is raised:


import unittest
class TestHangsForever(unittest.IsolatedAsyncioTestCase):
    async def test_hangs_forever(self):
        raise BaseException("Hangs forever")
if __name__ == "__main__":
    import unittest
    unittest.main()

A kind of similar issue present on 3.7 was fixed on 3.8 here https://github.com/python/cpython/blob/3.8/Lib/asyncio/events.py#L84, where BaseExceptions would not be correctly handled by the event loop, this seems somewhat related.

I had a look at IsolatedAsyncioTestCase implementation, did not spot any obvious broken thing there, I could use some light here. Thanks.
msg379670 - (view) Author: Lisa Roach (lisroach) * (Python committer) Date: 2020-10-26 16:28
New changeset 8374d2ee1589791be8892b00f4bbf8121dde24bd by Lisa Roach in branch 'master':
bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
https://github.com/python/cpython/commit/8374d2ee1589791be8892b00f4bbf8121dde24bd
msg383195 - (view) Author: miss-islington (miss-islington) Date: 2020-12-16 17:56
New changeset 9d409d6b474c188feca6213b9601e06f97715b72 by Miss Islington (bot) in branch '3.9':
bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
https://github.com/python/cpython/commit/9d409d6b474c188feca6213b9601e06f97715b72
msg383196 - (view) Author: miss-islington (miss-islington) Date: 2020-12-16 17:57
New changeset d549d0b5575b390431b7b26999151f79f74d4516 by Miss Islington (bot) in branch '3.8':
bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
https://github.com/python/cpython/commit/d549d0b5575b390431b7b26999151f79f74d4516
msg387887 - (view) Author: Russell Owen (r3owen) * Date: 2021-03-02 00:30
Here is a variant that also hangs, I suspect for the same reason. The task raises asyncio.CancelledError which inherits from BaseException and my guess is it somehow kills the event loop.

import asyncio
import unittest


class DemonstrateHang(unittest.IsolatedAsyncioTestCase):
    async def test_hang(self):
        task = asyncio.create_task(asyncio.sleep(2))
        await asyncio.sleep(0.1)
        task.cancel()
        await task
        # this also hangs: await asyncio.wait_for(task, 5)
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83282
2021-03-02 00:30:08r3owensetnosy: + r3owen
messages: + msg387887
2020-12-16 17:57:31miss-islingtonsetmessages: + msg383196
2020-12-16 17:56:21miss-islingtonsetmessages: + msg383195
2020-10-26 16:29:40lisroachsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-10-26 16:28:47miss-islingtonsetpull_requests: + pull_request21904
2020-10-26 16:28:39miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request21903
2020-10-26 16:28:33lisroachsetmessages: + msg379670
2020-10-11 21:41:00lisroachsetkeywords: + patch
nosy: + lisroach

pull_requests: + pull_request21630
stage: patch review
2019-12-19 19:55:52fornellassettype: crash
2019-12-19 19:44:59fornellascreate