classification
Title: "The loop argument is deprecated" reported when user code does not use it
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: asvetlov, lukasz.langa, mcepl, miss-islington, serhiy.storchaka, yselivanov
Priority: release blocker Keywords: patch

Created on 2021-09-04 02:41 by yan12125, last changed 2021-10-30 12:40 by yan12125. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28153 merged serhiy.storchaka, 2021-09-04 13:04
PR 28154 merged serhiy.storchaka, 2021-09-04 13:24
PR 28159 merged miss-islington, 2021-09-04 17:55
PR 28236 merged serhiy.storchaka, 2021-09-08 11:22
Messages (7)
msg401032 - (view) Author: Chih-Hsuan Yen (yan12125) * Date: 2021-09-04 02:41
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 issue44815.

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.
msg401044 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-04 13:09
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.
msg401049 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-04 17:54
New changeset c967bd523caabb05bf5988449487d7c1717f3ac6 by Serhiy Storchaka in branch '3.9':
[3.9] bpo-45097: Remove incorrect deprecation warnings in asyncio. (GH-28153)
https://github.com/python/cpython/commit/c967bd523caabb05bf5988449487d7c1717f3ac6
msg401050 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-04 17:55
New changeset c2970fdec52788b6d9ff419ab7e31f255d87433d by Serhiy Storchaka in branch 'main':
bpo-45097: Add more tests for shutdown_asyncgens() (GH-28154)
https://github.com/python/cpython/commit/c2970fdec52788b6d9ff419ab7e31f255d87433d
msg401057 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-04 20:38
New changeset 2ad114ddffbeeef1d20f26571b85a66974295667 by Miss Islington (bot) in branch '3.10':
[3.10] bpo-45097: Add more tests for shutdown_asyncgens() (GH-28154) (GH-28159)
https://github.com/python/cpython/commit/2ad114ddffbeeef1d20f26571b85a66974295667
msg401067 - (view) Author: Chih-Hsuan Yen (yan12125) * Date: 2021-09-05 02:36
Many thanks for the fast and great fix!
msg401394 - (view) Author: Ɓukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-08 15:59
New changeset a328a13b70ea0b0bec8b9d1b0067628369cabea9 by Serhiy Storchaka in branch '3.9':
[3.9] bpo-45097: Fix deprecation warnings in test_asyncio (GH-28236)
https://github.com/python/cpython/commit/a328a13b70ea0b0bec8b9d1b0067628369cabea9
History
Date User Action Args
2021-10-30 12:40:01yan12125setnosy: - yan12125
2021-10-30 12:30:39mceplsetnosy: + mcepl
2021-09-08 15:59:50lukasz.langasetmessages: + msg401394
2021-09-08 11:22:11serhiy.storchakasetpull_requests: + pull_request26656
2021-09-05 02:36:01yan12125setmessages: + msg401067
2021-09-04 20:38:44serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-09-04 20:38:04serhiy.storchakasetmessages: + msg401057
2021-09-04 17:55:53miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request26591
2021-09-04 17:55:23serhiy.storchakasetmessages: + msg401050
2021-09-04 17:54:54serhiy.storchakasetmessages: + msg401049
2021-09-04 13:24:26serhiy.storchakasetpull_requests: + pull_request26590
2021-09-04 13:09:27serhiy.storchakasetpriority: normal -> release blocker
nosy: + lukasz.langa
messages: + msg401044

2021-09-04 13:04:47serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request26589
2021-09-04 09:18:28serhiy.storchakasetassignee: serhiy.storchaka
2021-09-04 07:36:00serhiy.storchakasetnosy: + serhiy.storchaka
2021-09-04 02:41:25yan12125create