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

if __name__ == '__main__' for main examples. #3775

Closed
samuelcolvin opened this issue May 16, 2019 · 4 comments · Fixed by #3788
Closed

if __name__ == '__main__' for main examples. #3775

samuelcolvin opened this issue May 16, 2019 · 4 comments · Fixed by #3788

Comments

@samuelcolvin
Copy link
Member

aio-libs/aiohttp-devtools#229

Would be useful if we wrapped web.run_app(app) if a main check:

if __name__ == '__main__':
    web.run_app(app)

To work with aiohttp-devtools and other such tools.

If you're happy with this I'll submit a PR.

@asvetlov
Copy link
Member

I quite don't follow what exact code should be wrapped?
Is it part of documentation?

@samuelcolvin
Copy link
Member Author

samuelcolvin commented May 16, 2019

sorry, yes in the documentation the server example should become:

from aiohttp import web

async def handle(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    return web.Response(text=text)

app = web.Application()
app.add_routes([web.get('/', handle),
                web.get('/{name}', handle)])

if __name__ == '__main__':
    web.run_app(app)

So that importing the module doesn't run the server.

here

@asvetlov
Copy link
Member

I'm fine with the proposal

@samuelcolvin
Copy link
Member Author

will do next week and fix my other PR.

NewUserHa added a commit to NewUserHa/aiohttp-devtools that referenced this issue May 16, 2019
samuelcolvin pushed a commit to aio-libs/aiohttp-devtools that referenced this issue May 17, 2019
@helpr helpr bot added the pr-available label May 21, 2019
@helpr helpr bot removed the pr-available label May 21, 2019
@helpr helpr bot added the pr-merged label May 21, 2019
asvetlov pushed a commit that referenced this issue May 21, 2019
(cherry picked from commit 506c244)

Co-authored-by: Samuel Colvin <[email protected]>
asvetlov added a commit that referenced this issue May 22, 2019
(cherry picked from commit 506c244)

Co-authored-by: Samuel Colvin <[email protected]>
@lock lock bot added the outdated label May 20, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants