Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coroutine is awaited despite an exception in run_until_complete() #83372

Closed
dkaveshnikov mannequin opened this issue Jan 2, 2020 · 9 comments
Closed

Coroutine is awaited despite an exception in run_until_complete() #83372

dkaveshnikov mannequin opened this issue Jan 2, 2020 · 9 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@dkaveshnikov
Copy link
Mannequin

dkaveshnikov mannequin commented Jan 2, 2020

BPO 39191
Nosy @asvetlov, @1st1, @miss-islington, @tirkarthi
PRs
  • bpo-39191: Don't spawn a task before failing with already running loop #17796
  • [3.8] bpo-39191: Don't spawn a task before failing (GH-17796). #17820
  • [3.7] bpo-39191: Don't spawn a task before failing (GH-17796). #17821
  • bpo-39191: Fix RuntimeWarning in asyncio test #17863
  • [3.8] bpo-39191: Fix RuntimeWarning in asyncio test (GH-17863) #17894
  • [3.7] bpo-39191: Fix RuntimeWarning in asyncio test (GH-17863) #17895
  • Files
  • test_event_loop.py: Snippet
  • 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 = 'https://github.com/asvetlov'
    closed_at = <Date 2020-01-07.14:55:35.158>
    created_at = <Date 2020-01-02.13:34:18.219>
    labels = ['3.8', 'type-bug', '3.7', '3.9', 'expert-asyncio']
    title = 'Coroutine is awaited despite an exception in run_until_complete()'
    updated_at = <Date 2020-01-07.14:55:35.157>
    user = 'https://bugs.python.org/dkaveshnikov'

    bugs.python.org fields:

    activity = <Date 2020-01-07.14:55:35.157>
    actor = 'asvetlov'
    assignee = 'asvetlov'
    closed = True
    closed_date = <Date 2020-01-07.14:55:35.158>
    closer = 'asvetlov'
    components = ['asyncio']
    creation = <Date 2020-01-02.13:34:18.219>
    creator = 'dkaveshnikov'
    dependencies = []
    files = ['48819']
    hgrepos = []
    issue_num = 39191
    keywords = ['patch']
    message_count = 9.0
    messages = ['359196', '359201', '359281', '359282', '359415', '359417', '359418', '359509', '359513']
    nosy_count = 5.0
    nosy_names = ['asvetlov', 'yselivanov', 'miss-islington', 'xtreak', 'dkaveshnikov']
    pr_nums = ['17796', '17820', '17821', '17863', '17894', '17895']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39191'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @dkaveshnikov
    Copy link
    Mannequin Author

    dkaveshnikov mannequin commented Jan 2, 2020

    Hi, I found that if to call run_until_complete() in the task while the event loop will be running, a coroutine sent to run_until_complete() will be performed despite the exception raised from run_until_complete().
    It seems to me, it would be better to cancel such a coroutine or just do nothing with it.

    @dkaveshnikov dkaveshnikov mannequin added 3.7 (EOL) end of life topic-asyncio type-bug An unexpected behavior, bug, or error labels Jan 2, 2020
    @asvetlov
    Copy link
    Contributor

    asvetlov commented Jan 2, 2020

    Agree, this is a bug.

    @asvetlov asvetlov added 3.8 only security fixes 3.9 only security fixes labels Jan 2, 2020
    @asvetlov
    Copy link
    Contributor

    asvetlov commented Jan 4, 2020

    New changeset 867d833 by Andrew Svetlov in branch '3.8':
    [3.8] bpo-39191: Don't spawn a task before failing (GH-17796) (GH-17820)
    867d833

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Jan 4, 2020

    New changeset 9c145e1 by Andrew Svetlov in branch '3.7':
    [3.7] bpo-39191: Don't spawn a task before failing (GH-17796) (bpo-17821)
    9c145e1

    @asvetlov asvetlov closed this as completed Jan 4, 2020
    @tirkarthi
    Copy link
    Member

    This commit seems to generate some warnings in the nested run_until_complete test. The check for running loop is now done at run_until_complete itself before going through the below code in it to create a future and raised a RuntimeError by run_forever as the test used to do. Not sure why CI doesn't have these warnings.

    PYTHONWARNINGS=always ./python.exe -m test test_asyncio -m test_run_until_complete_nesting
    0:00:00 load avg: 2.16 Run tests sequentially
    0:00:00 load avg: 2.16 [1/1] test_asyncio
    /Users/kasingar/stuff/python/cpython/Lib/traceback.py:220: RuntimeWarning: coroutine 'EventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro1' was never awaited
      tb.tb_frame.clear()
    RuntimeWarning: Enable tracemalloc to get the object allocation traceback
    /Users/kasingar/stuff/python/cpython/Lib/traceback.py:220: RuntimeWarning: coroutine 'EventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro1' was never awaited
      tb.tb_frame.clear()
    RuntimeWarning: Enable tracemalloc to get the object allocation traceback
    /Users/kasingar/stuff/python/cpython/Lib/traceback.py:220: RuntimeWarning: coroutine 'EventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro1' was never awaited
      tb.tb_frame.clear()
    RuntimeWarning: Enable tracemalloc to get the object allocation traceback

    == Tests result: SUCCESS ==

    1 test OK.

    Total duration: 164 ms
    Tests result: SUCCESS

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Jan 6, 2020

    Ooh, you are right.
    The warning is printed only, test runner thinks that the test is ok.
    I'll prepare a quick fix.

    @asvetlov asvetlov reopened this Jan 6, 2020
    @asvetlov asvetlov self-assigned this Jan 6, 2020
    @asvetlov
    Copy link
    Contributor

    asvetlov commented Jan 6, 2020

    Thanks for the report!

    @miss-islington
    Copy link
    Contributor

    New changeset 10ac0cd by Miss Islington (bot) (Andrew Svetlov) in branch 'master':
    bpo-39191: Fix RuntimeWarning in asyncio test (GH-17863)
    10ac0cd

    @asvetlov
    Copy link
    Contributor

    asvetlov commented Jan 7, 2020

    New changeset 4112a3d by Andrew Svetlov in branch '3.8':
    [3.8] bpo-39191: Fix RuntimeWarning in asyncio test (GH-17863) (bpo-17894)
    4112a3d

    @asvetlov asvetlov closed this as completed Jan 7, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants