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

Recommended way to run background tasks #3459

Closed
arlyon opened this issue Dec 22, 2018 · 7 comments
Closed

Recommended way to run background tasks #3459

arlyon opened this issue Dec 22, 2018 · 7 comments
Labels

Comments

@arlyon
Copy link

arlyon commented Dec 22, 2018

app['redis_listener'] = app.loop.create_task(listen_to_redis(app))

The loop property on the Application class is now deprecated (#3374), but the docs still reference adding background tasks to the loop via this property. What is the recommended way to do that now?

@kxepal
Copy link
Member

kxepal commented Dec 22, 2018

aiojobs perfectly handles this problem.

@aio-libs-bot
Copy link

GitMate.io thinks the contributors most likely able to help are @asvetlov, and @aio-libs-bot.

Possibly related issues are #2246 (What's the recommended way of passing information to middlewares), #1104 (Rewrite doc section about background tasks), #3401 (Run background task in master process?), #2375 (add a way to run an app asynchron), and #2745 (Running out of memory ).

@arlyon
Copy link
Author

arlyon commented Dec 22, 2018

Great, should I update the docs to make mention of this, and remove the current (deprecated) method?

@kxepal
Copy link
Member

kxepal commented Dec 22, 2018

I don't think that the current method should be removed since it's works out of the box, but it might be good to mention how aiojobs may help there and why it's better. @asvetlov, what do you think about that?

@asvetlov
Copy link
Member

aiojobs is referenced at the begin of https://docs.aiohttp.org/en/stable/web_advanced.html

Deprecated app.loop usage should be removed from docs, sure.
The question is what is a replacement?
In Python 3.7+ there is a bare asyncio.create_task() but older pythons should use loop.create_task() with getting a loop instance by asyncio.get_event_loop().
I prefer Python 3.7 approach personally but will we confuse people?

@asvetlov
Copy link
Member

Doc is fixed by #3529

@lock
Copy link

lock bot commented Jan 14, 2020

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 Jan 14, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 14, 2020
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

4 participants