Skip to content

[3.9] bpo-44815: Always show deprecation in asyncio.gather/sleep() #27569

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

Merged
merged 8 commits into from
Aug 18, 2021

Conversation

Dreamsorcerer
Copy link
Contributor

@Dreamsorcerer Dreamsorcerer commented Aug 2, 2021

@ambv ambv changed the title bpo-44815: Always show deprecation in asyncio.gather/sleep() [3.9] bpo-44815: Always show deprecation in asyncio.gather/sleep() Aug 3, 2021
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A change in gather() LGTM, but useless get_running_loop() is called for sleep(0). I suggest to change the code in the same way as in gather():

if loop is not None:
    warnings.warn(...)
if delay <= 0:
    ...
if loop is None:
    ...

It will add smaller overhead.

@ambv
Copy link
Contributor

ambv commented Aug 3, 2021

Serhiy is right, and additionally we need to silence all the new warnings in test_asyncio and test_asyncgen. I'm looking into that since it's a bit tricky.

@serhiy-storchaka
Copy link
Member

I'm looking into that since it's a bit tricky.

How was it solved in 3.10? If the corresponding test code (for loop is not None) was just removed or wrapped with assertRaises(TypeError), we should just wrap it with assertWarns(DeprecationWarning). If it was rewritten in a way that does not pass a loop, we perhaps need to backport these changes.

@ambv
Copy link
Contributor

ambv commented Aug 6, 2021

How was it solved in 3.10?

The deprecations reached their EOL and functionality was removed. But it's a problem that will return so I think it's worth approaching systematically. We will need something like GH-27634 to do it.

@ambv ambv added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 17, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @ambv for commit 783e66c 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 17, 2021
Additional improvements:

- messages which were compiled regular expressions aren't unpacked back into
  strings for unmatched warnings;

- removed unnecessary "if tokens:" check (there's one before the for loop).
@ambv ambv added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 17, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @ambv for commit 217c789 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 17, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @ambv for commit d234e0d 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@ambv ambv added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 18, 2021
@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Aug 18, 2021
@ambv ambv merged commit b2779b2 into python:3.9 Aug 18, 2021
@TBBle
Copy link

TBBle commented Sep 1, 2021

I think this has introduced an unavoidable deprecation warning in BaseEventLoop.create_server(..., start_serving=True), which is the default value of start_serving:

https://github.com/python/cpython/blob/v3.9.7/Lib/asyncio/base_events.py#L1514-L1518

        if start_serving:
            server._start_serving()
            # Skip one loop iteration so that all 'loop.add_reader'
            # go through.
            await tasks.sleep(0, loop=self)

It also appears to affect Server.start_serving, which does the same thing, and from a brief glance, self._loop here is not going to be None.

https://github.com/python/cpython/blob/v3.9.7/Lib/asyncio/base_events.py#L349-L353

    async def start_serving(self):
        self._start_serving()
        # Skip one loop iteration so that all 'loop.add_reader'
        # go through.
        await tasks.sleep(0, loop=self._loop)

Edit: Late update, this new failure was also reported as https://bugs.python.org/issue45097 and fixed in 3.9.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants