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 documentation on "Background tasks" is wrong #1964

Closed
cecton opened this issue Jun 7, 2017 · 4 comments
Closed

The documentation on "Background tasks" is wrong #1964

cecton opened this issue Jun 7, 2017 · 4 comments
Labels

Comments

@cecton
Copy link
Contributor

cecton commented Jun 7, 2017

Long story short

In the example provided here: https://github.com/aio-libs/aiohttp/blob/master/docs/web.rst#background-tasks we add a new key to the application which is a background task.

If you activate the warnings using -Wdefault and execute the script, you will get:

/tmp/b.py:15: DeprecationWarning: Changing state of started or joined application is deprecated

Expected behaviour

Not sure. Not having the warning? The example doesn't look bad, only make_handler is called before the on_startup signal which freezes the app before the signal is sent.

Actual behaviour

When the example in the doc is executed, you get the warning.

Steps to reproduce

I made this variant to test it out:

import asyncio
from aiohttp import web


async def listen_to_redis(app):
    try:
        await asyncio.sleep(200)
    except asyncio.CancelledError:
        pass
    finally:
        print("cleanup")


async def start_background_tasks(app):
    app['redis_listener'] = app.loop.create_task(listen_to_redis(app))


async def cleanup_background_tasks(app):
    app['redis_listener'].cancel()
    await app['redis_listener']


app = web.Application()
app.on_startup.append(start_background_tasks)
app.on_cleanup.append(cleanup_background_tasks)
web.run_app(app)

And run: python -Wdefault <script>.py

Your environment

Python 3.6, Arch Linux

@asvetlov
Copy link
Member

asvetlov commented Jun 7, 2017

The warning should be relaxed: see #1947

@cecton
Copy link
Contributor Author

cecton commented Jun 7, 2017

Okay good to know thanks.

@asvetlov
Copy link
Member

Fixed

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants