Skip to content

IsolatedAsyncioTestCase freezes when exception is raised #83282

Description

@fornellas
mannequin
BPO 39101
Nosy @asvetlov, @1st1, @lisroach, @miss-islington, @fornellas, @r-owen
PRs
  • bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. #22654
  • [3.9] bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654) #22988
  • [3.8] bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654) #22989
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-10-26.16:29:40.338>
    created_at = <Date 2019-12-19.19:44:59.009>
    labels = ['3.8', 'type-crash', 'expert-asyncio']
    title = 'IsolatedAsyncioTestCase freezes when exception is raised'
    updated_at = <Date 2021-03-02.00:30:08.714>
    user = 'https://github.com/fornellas'

    bugs.python.org fields:

    activity = <Date 2021-03-02.00:30:08.714>
    actor = 'r3owen'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-10-26.16:29:40.338>
    closer = 'lisroach'
    components = ['asyncio']
    creation = <Date 2019-12-19.19:44:59.009>
    creator = 'fornellas'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39101
    keywords = ['patch']
    message_count = 5.0
    messages = ['358690', '379670', '383195', '383196', '387887']
    nosy_count = 6.0
    nosy_names = ['asvetlov', 'yselivanov', 'lisroach', 'miss-islington', 'fornellas', 'r3owen']
    pr_nums = ['22654', '22988', '22989']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue39101'
    versions = ['Python 3.8']

    Activity

    1. fornellas commented on Dec 19, 2019

      fornellasmannequin
      MannequinAuthor

      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.

    2. lisroach commented on Oct 26, 2020

      @lisroach
      Contributor

      New changeset 8374d2e by Lisa Roach in branch 'master':
      bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
      8374d2e

    3. miss-islington commented on Dec 16, 2020

      @miss-islington
      Contributor

      New changeset 9d409d6 by Miss Islington (bot) in branch '3.9':
      bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
      9d409d6

    4. miss-islington commented on Dec 16, 2020

      @miss-islington
      Contributor

      New changeset d549d0b by Miss Islington (bot) in branch '3.8':
      bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
      d549d0b

    5. r-owen commented on Mar 2, 2021

      r-owenmannequin
      Mannequin

      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)
    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of lifetopic-asynciotype-crashA hard crash of the interpreter, possibly with a core dump

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions