Navigation Menu

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

"The loop argument is deprecated" reported when user code does not use it #89260

Closed
yan12125 mannequin opened this issue Sep 4, 2021 · 7 comments
Closed

"The loop argument is deprecated" reported when user code does not use it #89260

yan12125 mannequin opened this issue Sep 4, 2021 · 7 comments
Assignees
Labels
3.9 only security fixes release-blocker topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@yan12125
Copy link
Mannequin

yan12125 mannequin commented Sep 4, 2021

BPO 45097
Nosy @mcepl, @asvetlov, @ambv, @serhiy-storchaka, @1st1, @miss-islington
PRs
  • [3.9] bpo-45097: Remove incorrect deprecation warnings in asyncio. #28153
  • bpo-45097: Add more tests for shutdown_asyncgens() #28154
  • [3.10] bpo-45097: Add more tests for shutdown_asyncgens() (GH-28154) #28159
  • [3.9] bpo-45097: Fix deprecation warnings in test_asyncio #28236
  • 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/serhiy-storchaka'
    closed_at = <Date 2021-09-04.20:38:44.608>
    created_at = <Date 2021-09-04.02:41:25.974>
    labels = ['type-bug', '3.9', 'release-blocker', 'expert-asyncio']
    title = '"The loop argument is deprecated" reported when user code does not use it'
    updated_at = <Date 2021-10-30.12:40:01.463>
    user = 'https://github.com/yan12125'

    bugs.python.org fields:

    activity = <Date 2021-10-30.12:40:01.463>
    actor = 'yan12125'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2021-09-04.20:38:44.608>
    closer = 'serhiy.storchaka'
    components = ['asyncio']
    creation = <Date 2021-09-04.02:41:25.974>
    creator = 'yan12125'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45097
    keywords = ['patch']
    message_count = 7.0
    messages = ['401032', '401044', '401049', '401050', '401057', '401067', '401394']
    nosy_count = 6.0
    nosy_names = ['mcepl', 'asvetlov', 'lukasz.langa', 'serhiy.storchaka', 'yselivanov', 'miss-islington']
    pr_nums = ['28153', '28154', '28159', '28236']
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45097'
    versions = ['Python 3.9']

    @yan12125
    Copy link
    Mannequin Author

    yan12125 mannequin commented Sep 4, 2021

    With Python 3.9.7, "DeprecationWarning: The loop argument is deprecated" may be reported when user code does not use it. Here is an example:

    import asyncio
    import warnings
    
    warnings.filterwarnings('error')
    
    def crash():
        raise KeyboardInterrupt
    
    async def main():
        asyncio.get_event_loop().call_soon(crash)
        await asyncio.sleep(5)

    try:
    asyncio.run(main())
    except KeyboardInterrupt:
    pass

    On 3.9.6, no warning is reported, while results on 3.9.7 are

    Traceback (most recent call last):
      File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
        return loop.run_until_complete(main)
      File "/usr/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
        self.run_forever()
      File "/usr/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
        self._run_once()
      File "/usr/lib/python3.9/asyncio/base_events.py", line 1890, in _run_once
        handle._run()
      File "/usr/lib/python3.9/asyncio/events.py", line 80, in _run
        self._context.run(self._callback, *self._args)
      File "/home/yen/var/local/Computer/archlinux/community/python-anyio/trunk/cpython-3.9.7-regression.py", line 11, in crash
        raise KeyboardInterrupt
    KeyboardInterrupt
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/yen/var/local/Computer/archlinux/community/python-anyio/trunk/cpython-3.9.7-regression.py", line 18, in <module>
        asyncio.run(main())
      File "/usr/lib/python3.9/asyncio/runners.py", line 47, in run
        _cancel_all_tasks(loop)
      File "/usr/lib/python3.9/asyncio/runners.py", line 64, in _cancel_all_tasks
        tasks.gather(*to_cancel, loop=loop, return_exceptions=True))
      File "/usr/lib/python3.9/asyncio/tasks.py", line 755, in gather
        warnings.warn("The loop argument is deprecated since Python 3.8, "
    DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.

    As indicated by the traceback, the loop argument is used inside the asyncio library, not from user code. It has been an issue for some time, and the issue is exposed after changes for bpo-44815.

    Credit: this example code is modified from an anyio test https://github.com/agronholm/anyio/blob/3.3.0/tests/test_taskgroups.py#L943. I noticed this issue when I was testing anyio against 3.9.7.

    @yan12125 yan12125 mannequin added 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error labels Sep 4, 2021
    @serhiy-storchaka
    Copy link
    Member

    There are several calls of gather() and sleep() with the loop argument from the asyncio library. Since all deprecation warnings were silenced in tests it was unnoticed.

    PR 28153 fixes the asyncio library, enables deprecation warnings in tests, fixes tests producing warnings and add several new tests for uncovered code. New tests will be ported to master later.

    @serhiy-storchaka
    Copy link
    Member

    New changeset c967bd5 by Serhiy Storchaka in branch '3.9':
    [3.9] bpo-45097: Remove incorrect deprecation warnings in asyncio. (GH-28153)
    c967bd5

    @serhiy-storchaka
    Copy link
    Member

    New changeset c2970fd by Serhiy Storchaka in branch 'main':
    bpo-45097: Add more tests for shutdown_asyncgens() (GH-28154)
    c2970fd

    @serhiy-storchaka
    Copy link
    Member

    New changeset 2ad114d by Miss Islington (bot) in branch '3.10':
    [3.10] bpo-45097: Add more tests for shutdown_asyncgens() (GH-28154) (GH-28159)
    2ad114d

    @yan12125
    Copy link
    Mannequin Author

    yan12125 mannequin commented Sep 5, 2021

    Many thanks for the fast and great fix!

    @ambv
    Copy link
    Contributor

    ambv commented Sep 8, 2021

    New changeset a328a13 by Serhiy Storchaka in branch '3.9':
    [3.9] bpo-45097: Fix deprecation warnings in test_asyncio (GH-28236)
    a328a13

    @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.9 only security fixes release-blocker topic-asyncio type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants